Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • slappy
    replied
    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:

    http://www.vbteam.info/how-to/32416-...variables.html



    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

    Leave a comment:


  • cbiweb
    replied
    Thanks, zoglair. I'll give it a try.

    Leave a comment:


  • zoglair
    replied
    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

    Leave a comment:


  • cbiweb
    replied
    Sooooooooo.... anyone know how to create a template hook?

    Leave a comment:


  • cbiweb
    replied
    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.

    Leave a comment:


  • Anseur
    replied
    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.

    Leave a comment:


  • Parture
    replied
    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?

    Leave a comment:


  • Anseur
    replied
    I don't see any non standard text near the bottom?

    Leave a comment:


  • 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?

    http://biblocality.com/forums/forum.php
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X