View Full Version : [HELP] replace template with template plugin
Dr.CustUmz
02-27-2016, 10:17 PM
i may have got it but it does not seem right to me, makes since, but doesnt seem right, can someone confirm this is the way or is there another way to do this.
$vbulletin->templatecache['forumhome_loggedinuser'] = fetch_template('drc_test');
---------
i am trying to completely replace the whole template (string) of forumhome_loggedinuser template
i have my hook set to
forumhome_start
and about all i can manage to do is add to it, replacing is new to me.
this is what i have currently
$drcrb_cr = '$stylevar[dirmark]';
$vbulletin->templatecache['forumhome_loggedinuser'] = str_replace($drcrb_cr,$drcrb_cr.fetch_template('dr c_test'),$vbulletin->templatecache['forumhome_loggedinuser']);
but i dont want to just add to it, i want to completely replace the forumhome_loggedinuser template with drc_test
MarkFL
02-28-2016, 02:43 AM
In one of my vB 3.8.x mods, I wanted to replace the output from the "newpost_threadmanage" template with the output from a custom template. The output from the default template is displayed in the "newreply" template in the variable $threadmanagement. So, what I did was create a plugin hooked at "newreply_form_complete" with the following PHP code:
if ($vbulletin->options['markfl_report_prefixes_enabled'])
{
eval('$new_template = "' . fetch_template('markfl_report_newpost_threadmanage ') . '";');
$threadmanagement = $new_template;
}
In vB 4.2.x you can more directly replace one template with another, but this was the workaround I devised for vB 3.8.x. :)
Dr.CustUmz
02-28-2016, 03:07 AM
ok so say i want to replace $activeusers on forumhome
with a template i define as $myTemplate
would it be the same process? and would the code i have in $myTemplate be able to run in replace of $activeusers (which is the forumhome_loggedinusers template) i still want the same variables to work like $loggedin[musername]
its mainly the hooks i get lost on i dont know what hooks i need to use for things i try to do so mainly i just try different ones untill it works
right now im using with the hook (forumhome_loggedinuser)
$vbulletin->templatecache['forumhome_loggedinuser'] = fetch_template('drc_act_av');
and that works, but its not really what i want it to do.
i want it to replace $activeusers on forumhome and load my template.
im thinking
eval('$drc_act_av = "' . fetch_template('drc_act_av') . '";');
$activeusers = $drc_act_av;
but would that work on forumhome_start hook, cause that template has to show $loggedin[musername] variables
MarkFL
02-28-2016, 03:24 AM
I would try the hook "forumhome_complete" hook location. See what you get...:)
Dr.CustUmz
02-28-2016, 03:56 AM
it works, but it breaks my other plugin, this is what i have
<plugin active="1" executionorder="5">
<title>DRC - Whos On Avatar</title>
<hookname>forumhome_loggedinuser</hookname>
<phpcode><![CDATA[require_once('./includes/functions_user.php');
$loggedin[avatarurl] = fetch_avatar_url($loggedin[userid]);
if (!$loggedin[avatarurl]) {
$loggedin[avatarurl] = $stylevar['imgdir_misc'] . '/noavatar.png';
} else {
$loggedin[avatarurl] = $vbulletin->options['bburl'] . '/' . $loggedin[avatarurl][0];
}]]></phpcode>
</plugin>
<plugin active="1" executionorder="5">
<title>DRC - Whos On Avatar FH</title>
<hookname>forumhome_complete</hookname>
<phpcode><![CDATA[
eval('$drc_act_av = "' . fetch_template('drc_act_av') . '";');
$activeusers = $drc_act_av;
]]></phpcode>
</plugin>
i have tried changing the first plugin to different hooks also, but i cant get it to load the variables i need it to
the html is spitting out
<!-- BEGIN TEMPLATE: drc_act_av -->
<a href="member.php?u="><img src="" height="40px" width="auto" border="0" alt=""></a>
<!-- END TEMPLATE: drc_act_av -->
when it should be: (in red)
<!-- BEGIN TEMPLATE: drc_act_av -->
<a href="member.php?u=12"><img src="avatars/users/12.gif?dateline=1456633560" height="40px" width="auto" border="0" alt=""></a>
<!-- END TEMPLATE: drc_act_av -->
doing both plugins in one how i had does work but again not the desired way
<plugin active="1" executionorder="5">
<title>DRC - Whos On Avatar</title>
<hookname>forumhome_loggedinuser</hookname>
<phpcode><![CDATA[require_once('./includes/functions_user.php');
$loggedin[avatarurl] = fetch_avatar_url($loggedin[userid]);
if (!$loggedin[avatarurl]) {
$loggedin[avatarurl] = $stylevar['imgdir_misc'] . '/noavatar.png';
} else {
$loggedin[avatarurl] = $vbulletin->options['bburl'] . '/' . $loggedin[avatarurl][0];
}
$vbulletin->templatecache['forumhome_loggedinuser'] = fetch_template('drc_act_av');]]></phpcode>
</plugin>
Simon Lloyd
03-11-2016, 03:01 AM
Have you tried changing the execution order?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.