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?
Creating a Template Hook for Some Text I want to add to my Forumhome page
Collapse
X
-
I don't see any non standard text near the bottom?MCO Raid Alliance - Shadowsong EU MCO guild home. -
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
-
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;
}
P.S.: Good for 3.x series - haven't checked on 4.x yetComment
-
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;
}
}
CheersSlappyComment
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Comment