I am trying to get my head around how to override the content displayed by a given block.  I have been testing with the preprocess function in my theme's template.php file but I am a bit confused on how to make it work for a given block.  I have the Devel module enabled and I can see for my header block:

<!-- FILE NAME SUGGESTIONS:
   * block-dynamic--system--header.tpl.php
   * block-dynamic--system.tpl.php
   * block--system:header.tpl.php
   x block-dynamic.tpl.php
-->

I created the following function in my template.php:

function themename_preprocess_block_dynamic(&$variables) {  
    if ($variables['block']->module == 'system') {
        switch ($variables['block']->delta) {
            case 'header':

           (code to set $variables['content'] here)

             break;

        }

     }

}

This will override the content for the header block.  What I am confusing myself with is how to override other blocks. My navigation block shows the following via the Devel module:

<!-- FILE NAME SUGGESTIONS:
   * block--menu--navigation.tpl.php
   * block--menu.tpl.php
   * block--menu:navigation.tpl.php
   x block.tpl.php
-->

Can I use the same function to override any of the blocks whether they are navigation, menus, views, custom blocks?  I have made several attempts at overriding different blocks with no success.  I am just trying to grasp what information I need when inspecting the page code with the extra information being added by the Devel module that will give my the ability to override the content of a given block.  

Sorry if I am a bit wordy....I am a newbie trying to learn so I can migrate several Drupal sites over to Backdrop.

Comments

Hello nhunt and welcome to the Backdrop Forum!

One important aspect to understand: preprocess functions are ONLY called if the corresponding template file (tpl.php) exists. If the template file doesn't exist, its preprocess function won't be called.

For example, the function function basis_preprocess_block__system__header()  placed in Basis' template.php file will only called if there is a template named block--system--header.tpl.php in the templates folder in Basis. This template, by the way, can be used to theme the header block of the site. If this file doesn't exist, then Backdrop would try to find block--system.tpl.php and its corresponding preprocess function mytheme_preprocess_block__system(). And if that file doesn't exist, then it will revert to using block.tpl.php and its corresponding preprocess mytheme_preprocess_block().

So, you CAN use block.tpl.php and its preprocess function mytheme_preprocess_block() to theme ALL blocks in your site, BUT if Backdrop finds a more granular template file somewhere in your theme's template folder, or somewhere in core, then it will use the more granular file and its preprocess function if it exists. For example, Backdrop provides (in core) block--system--powered-by.tpl.php. So, your site will use that template file to theme the "Powered by" block, AND will ONLY use the corresponding preprocess file named mytheme_preprocess_block__system__powered_by() (and will ignore  mytheme_preprocess_block() in this case).

Another important point. If you provide block--system--header.tpl.php but DON'T provide mytheme_preprocess_block__system__header(), its parent preprocess function will NOT be called (that is, mytheme_preprocess_block__system() is not called in this case, since Backdrop is expecting the full name for the preprocess function)

I hope this helps. Feel free to write followup questions.

One correction to my answer above:

mytheme_preprocess_block() seems to be called for all blocks, even if their templates are overridden.  

Thank you so much for that!  It has resolved my issue and got me going again!