Creating a Template Hook for Some Text I want to add to my Forumhome page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Parture
    Senior Member
    • Sep 2005
    • 364
    • 4.2.x

    Creating a Template Hook for Some Text I want to add to my Forumhome page

    How do I hook some text to go at the bottom of my forumhome page? See the text I created at the bottom of my page. I would like to make it into a $xxxx hook (I hope I am using that term properly) so I don't have to insert the text into my footer or forumhome page manually. Does anyone know how I can create a simple plugin and template for this?

    Discuss overcoming in Christ and how the Apostles and Elders organize the Church.
  • Anseur
    Senior Member
    • Jun 2004
    • 130
    • 4.1.x

    #2
    I don't see any non standard text near the bottom?
    MCO Raid Alliance - Shadowsong EU MCO guild home.

    Comment

    • Parture
      Senior Member
      • Sep 2005
      • 364
      • 4.2.x

      #3
      Oh I haven't but the text back in since Beta 5. So how do you put some text on a particular page (e.g. bottom of the forumhome page) by creating a hook for it instead of manually entering that text on the page?

      Comment

      • Anseur
        Senior Member
        • Jun 2004
        • 130
        • 4.1.x

        #4
        Well, if you look in the templates, you can see the hooks, so if you can find the template for where you want to put something, you can tell by the template hook to use.
        MCO Raid Alliance - Shadowsong EU MCO guild home.

        Comment

        • cbiweb
          Senior Member
          • Apr 2004
          • 2658
          • 4.1.x

          #5
          I believe what Parture is asking, is how to create a template hook, not how to use an existing one. I'd like to know that myself.
          ~ Life isn't always fair, but you can be. ~

          Comment

          • cbiweb
            Senior Member
            • Apr 2004
            • 2658
            • 4.1.x

            #6
            Sooooooooo.... anyone know how to create a template hook?
            ~ Life isn't always fair, but you can be. ~

            Comment

            • zoglair
              New Member
              • Dec 2007
              • 26

              #7
              The way I do it is via a plugin hooked on the "global_start". The code is as following:

              PHP Code:
              $z_name 'FORUMHOME';

              if (isset(
              $vbulletin->templatecache[$z_name]))
              {
                  
              $z_temp $vbulletin->templatecache[$z_name];

                  
              // do whatever changes in $z_temp
                 
                  
              $vbulletin->templatecache[$z_name] = $z_temp;

              I repeat the above code snippet for every template I am interested in changing. This is the way I implement skins (and other stuff) without modifying (statically) the templates.


              P.S.: Good for 3.x series - haven't checked on 4.x yet

              Comment

              • cbiweb
                Senior Member
                • Apr 2004
                • 2658
                • 4.1.x

                #8
                Thanks, zoglair. I'll give it a try.
                ~ Life isn't always fair, but you can be. ~

                Comment

                • slappy
                  Senior Member
                  • Apr 2003
                  • 1206

                  #9
                  Hi

                  Yes, that code will work for modifying templates and I recently used it quite a bit, thanks for posting that. However there is one caveat that is perhaps unique with 4.x. You won't find the templates in $vbulletin->templatecache (and the IF statement will fail) unless you precache them yourself.

                  You can do this with a plugin hook at fetch_hook('cache_templates'), located in class_bootstrap.php. Create a php statement like this to include every standard, as well as custom template you might be working with in other plugins:

                  PHP Code:
                  $cache array_merge(
                      array(
                  'FORUMHOME'),
                      array(
                  'navbar'),
                      array(
                  'Custom_FORUMHOME_header_pos1'),
                      array(
                  'Custom_FORUMHOME_header_pos2')
                  ); 

                  The majority of templates can then be modified in a plugin hook at 'process_templates_complete', or elsewhere if better suited. See this link for an explanation of using template variables:





                  Here is an example where I added 2 custom templates, registered as a single variable defining a template hook, and inserted in the FORUMHOME template just below the navbar.

                  The dynamically modified FORUMHOME template code will look like this

                  PHP Code:

                      
                  ' . $header . '

                      ' . $navbar . '' . $template_hook[FORUMHOME_customheader] . ' 


                  Here is the 'process_templates_complete' plugin code:

                  PHP Code:

                  // Templates for custom messages below navbar on Forum page

                  if(THIS_SCRIPT == index)
                  {
                      
                      
                  // Register several templates into one custom template hook location
                     
                      
                  $template_hook_name 'FORUMHOME_customheader';
                      
                      
                  // Custom message 1
                      
                      
                  $templater vB_Template::create('Custom_FORUMHOME_header_pos1'); 
                      
                  $template_hook[$template_hook_name] .= $templater->render();
                      
                      
                  // Custom message 2

                      
                  $templater vB_Template::create('Custom_FORUMHOME_header_pos2');
                       
                          
                  // Register variables that will be used in template (defined elsewhere) 
                          
                  $templater->register('var1'$var1);
                          
                      
                  $template_hook[$template_hook_name] .= $templater->render();



                      
                  // Add template hook to FORUMHOME template    

                      // Modify template dynamically - insert custom template hook

                      
                  $z_name 'FORUMHOME';

                      if (isset(
                  $vbulletin->templatecache[$z_name]))
                      {
                          
                  $z_temp $vbulletin->templatecache[$z_name];
                       
                          
                  // do whatever changes in $z_temp

                          // preg_replace syntax for ' . $navbar . '
                          
                  $str_search '/\' \. \$navbar \. \'/';

                          
                  $original_replace "' . \$navbar . '";              
                              
                          
                  $str_add "' . \$template_hook[$template_hook_name] . '";       

                      
                          
                  $z_temp preg_replace($str_search$original_replace $str_add$z_temp);
                          
                   
                          
                  // Replace modified FORUMHOME template
                          
                          
                  $vbulletin->templatecache[$z_name] = $z_temp;

                      }


                  Cheers
                  Slappy

                  Comment

                  widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                  Working...