PDA

View Full Version : function to include code on templates


Scanu
07-27-2012, 07:38 PM
Hi i'm trying to make a function for editing templates this is what i make

require_once(DIR . '/includes/class_template_parser.php');
function template_include ($template_name,$code,$position) {
$parser = new vB_TemplateParser($code);
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
if ($position = 'end'){
$include = ' $final_rendered .= \' '.trim($parser->_parse_nodes($parser->dom_doc->childNodes())).'\'; ';
$vbulletin->templatecache[''.$template_name] .= $include;
} else {
$include = '$final_rendered = \' '.trim($parser->_parse_nodes($parser->dom_doc->childNodes())) . '\' . ';
$vbulletin->templatecache[''.$template_name] = substr_replace($vbulletin->templatecache[''.$template_name], $include, 0, 17);
}
}
template_include('header','test','end');


but it doesn't work it seems that "$vbulletin->templatecache[''.$template_name] .= $include;" doesn't work in a function.. where am i wrong :S

--------------- Added 1343499648 at 1343499648 ---------------

The variable $vbulletin->templatecache['.....'] isn't working in a function! Why? :(

Badshah93
07-29-2012, 05:43 PM
globalize $vbulletin inside a function.

global $vbulletin;

Sarteck
08-01-2012, 09:41 AM
Also, isn't $vbulletin->templatecache[''.$template_name] the same thing as $vbulletin->templatecache[$template_name]? X3 Why prepend an empty string literal to it?

Scanu
08-01-2012, 10:04 AM
That was a test, because in '' i should put prefix of template however thanks the code works $vbulletin isn't a variable declared on the function so i have to globalize it