Template error - failed to find block ... or How to modify SYS_MENU or SUB_MENU Template error - failed to find block ... or How to modify SYS_MENU or SUB_MENU
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Template error - failed to find block ... or How to modify SYS_MENU or SUB_MENU

Started by Paver, January 24, 2006, 06:50:54 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Paver

In customizing a theme in 1.4.x or upgrading a theme from a previous version, many people are seeing the error message "Template error - failed to find block BLOCK_ID", where BLOCK_ID is one of the buttons/links on the SYS_MENU or SUB_MENU, or one of the other template variables.  This post will describe in detail why this error occurs and how to properly customize your SYS_MENU or SUB_MENU.  These techniques can easily be applied to the other template variables that give this error.

The first thing you need to do is to find out where the BLOCK_ID mentioned in the error message is found.  Go to the sample/theme.php and search for the BLOCK_ID.  Look on the line or above the line where BLOCK_ID is mentioned to figure out which template variable is the relevant one.  If the template variable is not the sys_menu or sub_menu, then you merely have to copy the template variable from sample/theme.php to your theme.php and customize the HTML as desired, leaving the BLOCK_ID lines alone.  Please still read the rest of this post so you understand why the error occurs.

In previous Coppermine versions, the SYS_MENU and SUB_MENU were defined by straight HTML in $template_sys_menu and $template_sub_menu respectively (see the 'hardwired' theme for a current theme that still uses straight HTML).  Coppermine 1.4.x uses a couple of shortcut functions to make modifying these menus more clear & organized, but it also makes it easier to break your theme if you don't understand what these shortcut functions do.  The main reason why you get the error message "Failed to find block" is that you removed or renamed a button/link that Coppermine expects to find in one of those menus.  If you want to remove a button, you instead need to make an empty button; you are required to leave the button label in place so that Coppermine knows where to find the button - even though it is an empty button.  It won't show up, as you want, but Coppermine will also be happy to know you specifically don't want that button instead of flaying around finding no clue if you really want to remove the button or merely neglected to specify one way or the other.  Receiving the error message "failed to find block" tells you that you did the latter.  You need to specifically say, in effect, "I want this button not to be displayed".  I hope that this is clear.  Everything described below depends on understanding what Coppermine expects from your custom theme.  Note that I'm describing here how to customize your theme.  Overall - not theme-related - the best way to remove Coppermine items is with this plugin: http://forum.coppermine-gallery.net/index.php?topic=26893.0.

In all theme customizations, you copy code from the sample/theme.php to your theme.php.  In case you skipped this step, please make sure you copied a theme to a new folder before you start to customize it.  If you are creating your own theme by customizing another, you need to create your own folder & theme name, for the sanity of all involved (and future clarity).  Do not copy the sample/theme.php; this theme includes all the customizations you can use in your theme - it's intended as a central repository to be copied from, not used directly.

Unlike other theme customizations, it's a bit more difficult to figure out which blocks to copy to customize the SYS_MENU and SUB_MENU (which are the labels used in template.html).  All other customizations have a single variable or function to copy and customize.  This one requires copying 2 functions and bunch of other lines.  Start by copying the whole block to your theme, starting from and including these 3 lines:
// Creates buttons from a template using an array of tokens
// this function is used in this file it needs to be declared before being called.
function assemble_template_buttons($template_buttons,$buttons) {

and continuing through and including these lines:

  $params = array('{BUTTONS}' => assemble_template_buttons($template_sub_menu_button,$sub_menu_buttons));
  $template_sub_menu = template_eval($template_sub_menu,$params);
}

This is a total of 94 lines (approximately - future releases may add or delete some).

A summary of this block is as follows:

  • function assemble_template_buttons
  • function addbutton
  • variable $template_sys_menu
  • variable $template_sub_menu
  • block to fill in $template_sys_menu
  • block to fill in $template_sub_menu

If you are upgrading your custom theme from a previous version, please refer to the documentation for upgrading themes.  Some of this block is described in the theme upgrade docs.  What I'll describe here supplements those docs but it doesn't replace them.

I'll describe how to customize the addbutton lines in the sys_menu and sub_menu blocks.  Here's one of those buttons:

    // {HREF_LNK}{HREF_TITLE}{HREF_TGT}{BLOCK_ID}{SPACER}
    addbutton($sys_menu_buttons,'{HOME_LNK}','{HOME_TITLE}','{HOME_TGT}','home',$template_sys_menu_spacer);


There are 6 parameters in the addbutton function.  The important ones to customize are the 2nd, 3rd, and 4th ones.  In order, they are:

  • {HREF_LNK} - the link text you see on the web page
  • {HREF_TITLE} - the title of the link, usually seen as a tooltip or mouse hover box
  • {HREF_TGT} - the URL of the link, i.e. the webpage to go to

The 5th parameter is the BLOCK_ID and must not be modified.  Coppermine uses the BLOCK_ID to identify this button and uses it when it wants to do something in the core code with this button.  In the example above, 'home' is the BLOCK_ID.  If for example you want to replace the home link with a link to your BBS so you can switch back & forth between your Coppermine gallery and your forum boards, replace the _LNK, _TITLE, and _TGT, but keep the BLOCK_ID as 'home' even though it might not be your home page.  If you want to add a link in addition to the home link, you add a new addbutton line in the appropriate place.  The curly braces in the default buttons are used by Coppermine as labels to be replaced with language-compatible text or URLs.  If you want to replace something with custom text & URL, do not use curly braces - just type in the text & URL in single quotes.  So, in this example, you would modify the home addbutton as follows:
addbutton($sys_menu_buttons,'Forum','Go to the forums.','../phpBB/index.php','home',$template_sys_menu_spacer);
As you see, I didn't touch the BLOCK_ID 'home'.

To remove menu items, you cannot comment out the relevant addbutton line.  If you do so, Coppermine cannot find the BLOCK_ID anymore because you have removed it completely by commenting it out.  A quick & dirty way to remove menu items is to send blank strings for the _LNK, _TITLE, and _TGT parameters along with the spacer parameter (the last one), leaving the BLOCK_ID alone as shown:
addbutton($sys_menu_buttons,'','','','home','');
This is dirty because it produces an empty <a href> tag which is not shown anywhere and doesn't cause display issues, but is not clean since it is there in the source of the web page.  The best way to remove menu buttons and any other Coppermine items is with the Final_Extract plugin, which removes the block after Coppermine has done its thing and just before it is to be displayed on the web page.  Here's the thread for the plugin: http://forum.coppermine-gallery.net/index.php?topic=26893.0.

So, what's the bottom line?  Leave the BLOCK_IDs intact for all theme variables, for those specified by HTML (using <!-- BEGIN BLOCK_ID --> and END comment tags), and for those specified by addbutton().  Modify the links, titles, and targets of those items you want to replace, but leave the BLOCK_ID alone so Coppermine knows you want to replace this BLOCK_ID.  To add items, insert new addbutton() lines and HTML as appropriate.  To remove items, use the plugin noted above, or use the quick & dirty method, but do not comment out the addbutton() line or remove the BEGIN & END tags.

p.s. If you want to customize the buttons to be images instead of text, you need to use straight HTML as exemplified in the 'hardwired' theme (and some other themes).  Respect the BLOCK_IDs and you'll be all set.

marvo

this is great except for the fact it says
// this function [i.e. addbutton()] is used in this file it needs to be declared before being called.

How do you declare the function? If I do as per your instructions, I end up with an error telling me I have an undefined function.

Paver

If you copy the whole block like I said, you'll include the function declaration for addbutton(), which is this part:
// Creates an array of tokens to be used with function assemble_template_buttons
// this function is used in this file it needs to be declared before being called.
function addbutton(&$menu,$href_lnk,$href_title,$href_tgt,$block_id,$spacer) {
  $menu[]=array($href_lnk,$href_title,$href_tgt,$block_id,$spacer);
}

marvo

Ah... you were right, I'd failed to notice the initial lines I'd copied where not the initial lines you'd indicated. However....all is not well. I've copied the following text from sample's theme.php and edited one button as a trial:

Quote// Creates buttons from a template using an array of tokens
// this function is used in this file it needs to be declared before being called.
function assemble_template_buttons($template_buttons,$buttons) {
    $counter=0;
    $output='';

    foreach ($buttons as $button)  {
      if (isset($button[4])) {
         $spacer=$button[4];
      } else {
      $spacer='';
      }

        $params = array(
            '{SPACER}'     => $spacer,
            '{BLOCK_ID}'   => $button[3],
            '{HREF_TGT}'   => $button[2],
            '{HREF_TITLE}' => $button[1],
            '{HREF_LNK}'   => $button[0]
            );
        $output.=template_eval($template_buttons, $params);
    }
    return $output;
}


// Creates an array of tokens to be used with function assemble_template_buttons
// this function is used in this file it needs to be declared before being called.
function addbutton(&$menu,$href_lnk,$href_title,$href_tgt,$block_id,$spacer) {
  $menu[]=array($href_lnk,$href_title,$href_tgt,$block_id,$spacer);
}


// HTML template for sys_menu
$template_sys_menu = <<<EOT
          {BUTTONS}
EOT;

// HTML template for sub_menu
$template_sub_menu = $template_sys_menu;

if (!defined('THEME_HAS_NO_SYS_MENU_BUTTONS')) {

  // HTML template for template sys_menu spacer
  $template_sys_menu_spacer ="::";

  // HTML template for template sys_menu buttons
  $template_sys_menu_button = <<<EOT
  <!-- BEGIN {BLOCK_ID} -->
        <a href="{HREF_TGT}" title="{HREF_TITLE}">{HREF_LNK}</a> {SPACER}
  <!-- END {BLOCK_ID} -->
EOT;

  // HTML template for template sys_menu buttons
    // {HREF_LNK}{HREF_TITLE}{HREF_TGT}{BLOCK_ID}{SPACER}
    addbutton($sys_menu_buttons,'Home Page','Home Page','../../../index.html','home',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{MY_GAL_LNK}','{MY_GAL_TITLE}','{MY_GAL_TGT}','my_gallery',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{MEMBERLIST_LNK}','{MEMBERLIST_TITLE}','{MEMBERLIST_TGT}','allow_memberlist',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{MY_PROF_LNK}','{MY_PROF_TITLE}','{MY_PROF_TGT}','my_profile',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{ADM_MODE_LNK}','{ADM_MODE_TITLE}','{ADM_MODE_TGT}','enter_admin_mode',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{USR_MODE_LNK}','{USR_MODE_TITLE}','{USR_MODE_TGT}','leave_admin_mode',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{UPL_PIC_LNK}','{UPL_PIC_TITLE}','{UPL_PIC_TGT}','upload_pic',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{REGISTER_LNK}','{REGISTER_TITLE}','{REGISTER_TGT}','register',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{FAQ_LNK}','{FAQ_TITLE}','{FAQ_TGT}','faq',$template_sys_menu_spacer);
    addbutton($sys_menu_buttons,'{LOGIN_LNK}','{LOGIN_TITLE}','{LOGIN_TGT}','login','');
    addbutton($sys_menu_buttons,'{LOGOUT_LNK}','{LOGOUT_TITLE}','{LOGOUT_TGT}','logout','');
    // Login and Logout don't have a spacer as only one is shown, and either would be the last option.

  $params = array('{BUTTONS}' => assemble_template_buttons($template_sys_menu_button,$sys_menu_buttons));
  $template_sys_menu = template_eval($template_sys_menu,$params);
}

As far as I can make out, this should be fine as it's what you ask me to copy but I'm still getting this error:
QuoteTemplate error
Failed to find block 'custom_link'(#(<!-- BEGIN custom_link -->)(.*?)(<!-- END custom_link -->)#s) in :

          {BUTTONS}

I've tried a number of variations but I'm getting no further. I'm using a customised Mac OX X theme and 1.4.5 which I've recently upgraded from 1.3.? I've read through the theme upgrade doc but I can't find anything that I thought was relevant to this i.e. had to be done in advance of this. Have I missed something? Thanx in advance.

insecure x blue

Can someone clearly explain all this to me because it's just flying over my head. I'm no computer whiz and the steps is confusing me. So I got the error but with this block id or whatever it is

QuoteTemplate error
Failed to find block 'report_file_button'(#(<!-- BEGIN report_file_button -->)(.*?)(<!-- END report_file_button -->)#s) in :

        <tr>
                <td align="center" valign="middle" class="navmenu" width="48">
                        <a href="{THUMB_TGT}" class="navmenu_pic" title="{THUMB_TITLE}"><img src="images/folder.gif" width="16" height="16" align="absmiddle" border="0" alt="{THUMB_TITLE}" /></a>
                </td>
                <td align="center" valign="middle" class="navmenu" width="48">
                        <a href="javascript:;" onClick="blocking('picinfo','yes', 'block'); return false;" title="{PIC_INFO_TITLE}"><img src="images/info.gif" width="16" height="16" border="0" align="absmiddle" alt="{PIC_INFO_TITLE}" /></a>
                </td>
                <td align="center" valign="middle" class="navmenu" width="48">
                        <a href="{SLIDESHOW_TGT}" title="{SLIDESHOW_TITLE}"><img src="images/slideshow.gif" width="16" height="16" border="0" align="absmiddle" alt="{SLIDESHOW_TITLE}" /></a>
                </td>
                <td align="center" valign="middle" class="navmenu" witdh="100%">
                        {PIC_POS}
                </td>
                <td align="center" valign="middle" class="navmenu" width="48">
                        <a href="{ECARD_TGT}" title="{ECARD_TITLE}"><img src="images/ecard.gif" width="16" height="16" border="0" align="absmiddle" alt="{ECARD_TITLE}" /></a>
                </td>
                <td align="center" valign="middle" class="navmenu" width="48">
                        <a href="{PREV_TGT}" class="navmenu_pic" title="{PREV_TITLE}"><img src="images/prev.gif" width="16" height="16" border="0" align="absmiddle" alt="{PREV_TITLE}" /></a>
                </td>
                <td align="center" valign="middle" class="navmenu" width="48">
                        <a href="{NEXT_TGT}" class="navmenu_pic" title="{NEXT_TITLE}"><img src="images/next.gif" width="16" height="16" border="0" align="absmiddle" alt="{NEXT_TITLE}" /></a>
                </td>
        </tr>



Yet I can't find that Block ID whatever it is in sample. Can someone please help me out?

marvo

Is anyone going to reply to my post above? I'm completely stuck and there's nowhere else I can go where I can find help.

Gau Gau, you only gave me half of what I need. If I'm doing something totally wrong, then kindly and patiently please point that out. Do I need to give you more info? THis is frustrating because it's so much different from Coppermine 1.3x that I'm in the dark.

CHeers...

Joachim Müller

basically, replying to a sticky thread that is labelled as "FAQ" with your individual support issues is what keeps me (or other supporters) from replying. It's people like you who don't respect board rules nor common sense who force us to lock down each and every sticky thread, although others (who don't seek individual support on a support thread, but are ready to share their thoughts on the sticky's content itself) might benefit if sticky threads stayed open.
This is quite a large support board - we'd like to think of it as a knowledge base. By cluttering threads you make the board less user-friendly, as others are forced to read your individual issues they probably are not interessted in. Review the board rules (you agreed to respect them when signing up) and keep out of this thread. Start your own thread instead, after having read the docs and after having searched exhaustively for your issues.

marvo

Apologies to GauGau and others for posting this in a sticky. I just thought that as that sticky topic was relevant it would be the best place to post further issues so that others can find it in the future. I was also led astray by the first reply I got. That made me think that posting was fine. This board seems to work differently from many I've been part of. You live and learn...

I've now posted my query HERE and I'd be grateful for replies to help me solve the problem.

Paver

My first reply about the function declaration was a clarification that I thought might be useful for others who don't know what a function declaration is.  I can see how you might think you could continue support here.

The general policy on this forum is "one issue per thread".  You should start your own thread for support and reference relevant threads in your first post.  If your support question is identical to an existing thread, go ahead and reply to it.  For sticky threads that covers lots of issues, we prefer you don't ask for individual support as GauGau said.  The intent is to develop the sticky thread for general use, not to provide individual support for lots of different issues in one thread.

One issue per thread keeps things organized and lets us "solve" issues one thread at a time. 

So, apology accepted.  Let's move on. 

bitcloud

Thanks, it worked no problems...

I can't work out how to modify the visibility of custom links however?
Eg if i want a link visible for logged in users only (and yes I have already spent large amounts of time searching the board  ;) )

I think if someone can elaborate on this topic and explain how to adjust custom link's visibility, it would definitely be sticky worthy...

Joachim Müller

The posting just above yours says that you mustn't try to hijack sticky threads with individual support requests. It's people like you who force us to lock down each and every sticky thread, stripping the possibility for people who would actually have a say in the issue discussed on the thread. Butt out of this thread. Start your own instead! >:(