PDA

View Full Version : str_replace and custom template


LifesGreatestGift
04-07-2012, 05:08 AM
What am I doing wrong? I would like to do a string replace on postbit/postbit_legacy template. Find specific code, insert my custom template after it. Here is what I have and its not working.


require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<span class="postcontrols">');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$templater = vB_Template::create('my_custom_template');
$parser = new vB_TemplateParser($templater);
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));
$vbulletin->templatecache['postbit'] = str_replace($find, $find . $replace, $vbulletin->templatecache['postbit']);
$vbulletin->templatecache['postbit_legacy'] = str_replace($find, $find . $replace, $vbulletin->templatecache['postbit_legacy']);
unset($find, $replace);

This is using parse_templates.

I tried this in postbit_display_complete and it doesnt work either.

$find = '<span class="postcontrols">';
$replace = vB_Template::create('my_custom_template');
$vbulletin->templatecache['postbit_legacy'] = str_replace($find, $find . $replace, $vbulletin->templatecache['postbit_legacy']);
$templater->render();
unset($find, $replace);

Any help would be appreciated.

kh99
04-07-2012, 05:23 AM
I'm not sure, but I think maybe you need:

$parser = new vB_TemplateParser($templater->render());


(the ->render() added), since the vB_TemplateParser constructor takes a string.

LifesGreatestGift
04-07-2012, 05:26 AM
in the current postbit_display_complete code I get this error

Catchable fatal error: Object of class vB_Template could not be converted to string

I need to be able to get a custom template and convert it into a string/variable.

--------------- Added 1333780042 at 1333780042 ---------------

and for some reason

$templater = vB_Template::create('my_custom_template');

doesnt work in parse_templates (the way I am using it)

kh99
04-07-2012, 05:35 AM
Hmm...this thread has some code for doing a replace: www.vbulletin.org/forum/showthread.php?t=264690 Maybe it's fetch_template_raw() that you're looking for.

LifesGreatestGift
04-07-2012, 05:51 AM
AWESOME! That worked!

parse_templates
$find_string = '<span class="postcontrols">';
$repl_string = vB_Template::fetch_template_raw('my_custom_templat e');
$vbulletin->templatecache['postbit_legacy'] = str_replace($find_string, $find_string . $repl_string, $vbulletin->templatecache['postbit_legacy']);

Pandemikk
04-07-2012, 07:05 AM
Just as a side note here,

Notice how it's usually: $templater = vB_Template::create();
Then: print_output($templater->render())

The method create() returns an object. $repl_string, in your code, was an object- which explains your fatal error.