Say I have a template file located here root/styles/prosilver/template/portal.html looking like this:
- Code: Select all
<div id="sidebar" class="left-box" style="width: 20%">
<!-- BEGIN sidebar -->
<div class="block'>
<h3>{sidebar.BLOCK_TITLE}</h3>
<span>{sidebar.BLOCK_CONTENT}</span>
</div>
<!-- END sidebar -->
</div>
<div id="main-content" class="left-box" style="width: 60%">
// stuff
</div>
The typical structure for the mod looks like this:
- Code: Select all
- root/
- modules/
- example_module/
- blocks/
- sample_block.php
- template/
- sample_block_template.html
Say the sample_block.php looks like this:
- Code: Select all
<?php
function portal_sample_block($row)
{
global $mtemplate, $phpbb_root_path;
$mtemplate->assign_vars(array(
'TEST1' => '1st test',
'TEST2' => '2nd test')
);
$tpl_path = $phpbb_root_path . 'modules/example_module/template/'
$mtemplate->set_custom_template($tpl_path, 'test');
$mtemplate->set_filenames(array('body' => 'sample_block_template.html'));
return array(
'title' => 'My sample block',
'content' => $mtemplate->assign_display('block')
);
}
?>
and sample_block_template.html
- Code: Select all
<div class="bg3">{TEST1}</div>
<div class="bg2">{TEST2}</div>
Then say I have this file that processes the blocks
- Code: Select all
$mtemplate = new template();
foreach ($block as $block_row)
{
$module = $row['module'];
$block_name = $row['block_name'];
$func = 'portal_' . $block_name;
if (!function_exists($func))
{
@include($phpbb_root_path . "modules/$module/blocks/$block_name.$phpEx");
}
//call block function
$data = $func($row);
$template->assign_block_vars('sidebar', array(
'BLOCK_TITLE' => $data['title'],
'BLOCK_CONTENT' => $data['content'])
);
$mtemplate->destroy();
}
This worked fine prior to 3.0.6. Blocks that use template->assign_block_vars seem to work fine but template->assign_vars is where I'm having problems after template->destroy is used.
I'd hate to take up your time if this is something that I caused myself but this worked before and I'm not sure what went wrong.
@blueray2048
I use a separate template object because I use template->assign_display(), and template->destroy on blocks which would clear out the template data. Hope I'm making sense.