Any suggestion why the code below does not works as expected?
PHP Code:
<plugin active="1" executionorder="20">
<title>Build Advertisments Block</title>
<hookname>cache_templates</hookname>
<phpcode><![CDATA[
global $db, $vbulletin;
$group = $vbulletin->db->query_first("SELECT * FROM ".TABLE_PREFIX."banners_groups WHERE active=1 ORDER BY lastshow ASC LIMIT 1");
$groupid = $group["id"];
$spots = $group["spots"];
$random = $group["random"];
$cellwidth = 100/$spots;
// Update Group with Last Show Time
$timenow = time();
$vbulletin->db->query_write("UPDATE ".TABLE_PREFIX."banners_groups SET lastshow=$timenow WHERE id=$groupid ORDER BY id ASC");
// List Group Advertisments
if ($random == 1)
{
$advertisments = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."banners_advertisers WHERE groupid=$groupid AND active=1 ORDER BY rand() LIMIT $spots");
} else {
$advertisments = $vbulletin->db->query_read("SELECT * FROM ".TABLE_PREFIX."banners_advertisers WHERE groupid=$groupid AND active=1 ORDER BY displayorder ASC LIMIT $spots");
}
$main_bit = '';
while ($advertisment = $vbulletin->db->fetch_array($advertisments)) {
// Prepare Templates
$templater = vB_Template::create('banners_main_bit');
$templater->register('htmlcode', htmlspecialchars_uni($advertisment[htmlcode]));
$templater->register('cellwidth', $cellwidth);
$main_bit .= $templater->render();
}
$templater = vB_Template::create('banners_main');
$templater->register('main_bit', $main_bit);
$templatevalues['mybanners'] = $templater->render();
vB_Template::preRegister('header', $templatevalues);
]]></phpcode>
</plugin>
Taking in account that:
- I used many different hooks like: global_start, global_complete, fetch_templates etc.
- I also used many different templates like: ad_global_header1 etc
- The same code with only difference the last 2 lines is working in php file if I use: print_output($templater->render());
Thank you very much
EDIT: What I was adding in the templates is: {vb:raw mybanners}