View Full Version : if ($show['forumdescription']) doesn't work in process_templates_complete
Scanu
12-21-2011, 07:18 PM
Ok the question is simple the conditional "if ($show['forumdescription'])" always retur false..
this code works
$replace = '<h2 class="forumtitle"><div id="scanu"><a ';
$replace .= 'title="<scanu>\' . $forum[\'description\'] . \'</scanu>" ';
$replace .= 'href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . \'">\' . $forum[\'title\'] . \'</a></div></h2>';
And this doen't work
$replace = '<h2 class="forumtitle"><div id="scanu"><a ';
if ($show['forumdescription']) {
$replace .= 'title="<scanu>\' . $forum[\'description\'] . \'</scanu>" ';
}
$replace .= 'href="\' . vB_Template_Runtime::linkBuild("forum", $forum) . \'">\' . $forum[\'title\'] . \'</a></div></h2>';
So I guess that's in a plugin using hook forumbit_display? The problem is that $show['forumdescription'] hasn't been set yet. But the line that sets it looks like this:
$show['forumdescription'] = ($forum['description'] != '' ? true : false);
so you should just be able to use $forum['description'] != '' instead.
Scanu
12-21-2011, 07:38 PM
No the hook is process_templates_complete (it is another plugin) however i'll try again
--------------- Added 1324500305 at 1324500305 ---------------
The same thing might work in that template, but you may need to add
global $forum;
to the beginning of the plugin code.
Scanu
12-21-2011, 07:47 PM
It return false even if there's a description :( that's my code
global $forum;
$show['forumdescription'] = ($forum['description'] != '' ? true : false);
$replace = '<h2 class="forumtitle"><div id="scanu"><a ';
if ($show['forumdescription']) {
$replace .= 'title="<scanu>\' . $forum[\'description\'] . \'</scanu>" ';
}
It could be that $forum isn't set yet, I'm not sure.
Oh...what are you doing with the value, are you changing a cached template? The problem probably is that displaying the forum page uses the template many times but process_templates_complete is only called once (I think). You'll probably have to figure out some other way of doing it. Maybe insert a variable into the template then set the variable from anotehr hook depending on the current value of $forum[description].
Scanu
12-21-2011, 08:42 PM
what hook for example? And the code would be something like this?
if ($show['forumdescription']) {
$description = true;
} else {
$description = false;
}
Do i understand you?
Right, but you'd have to get that in the template so that it all ran OK. I really can't tell you which hook to use without knowing exactly what you're trying to do. Just try to find a hook that's called each time that template is used.
Scanu
12-21-2011, 09:21 PM
you'd have to get that in the template so that it all ran OK
What do you mean?
Are you trying to modify a cached template?
Scanu
12-21-2011, 09:44 PM
Yes forumhome_forumbit_level2_post
Right, OK, so I meant that you should modify the template and put in code with an "if" instead of a constant string. Maybe that's what you meant - the 'if' has to be part of the template string, and you have to make sure the string ends up being valid php code.
I think we already decided that $show['forumdescription'] isn't set yet when that template is used, so don't use that as your condition. Use if ($forum['description'] != '') {do something}.
Now that I think about it, I guess you *can* use process_templates_complete since what you want to do is change the template once. You can pretty much do the same thing, you just have to change your replace code and take it out of the 'if'.
Sorry if I confused you before.
BTW, did you read this thread: https://vborg.vbsupport.ru/showthread.php?t=275713 ? He was trying to do exactly the same thing you're doing.
Scanu
12-21-2011, 10:02 PM
Ok that is his code
$replace = '<span class="date">\';if($post[\'isfirstshown\']) { $final_rendered .=\'' . $fetch['data'] . '\'; } $final_rendered .=\'';
Now let's go back to my code, was
$replace = '<h2 class="forumtitle"><div id="scanu"><a ';
if ($show['forumdescription']) {
$replace .= 'title="<scanu>\' . $forum[\'description\'] . \'</scanu>" ';
}
now i've edited this code to
$replace = '<h2 class="forumtitle"><div id="scanu"><a\';if ($show[\'forumdescription\']) {
//'til now all is ok but then i don't know what to do because i don't understand "Information4ever"'s code, can you help me?
//this is the remaining code
$replace .= 'title="<scanu>\' . $forum[\'description\'] . \'</scanu>" ';}
Thanks for your help kh99 :)
--------------- Added 1324593817 at 1324593817 ---------------
Someone can help me?
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.