PDA

View Full Version : Modify template by install code


Valter
12-27-2011, 12:09 PM
I want to do simple search/replace in the template on product install.

It works fine, however until it's re-saved manually changes are not visible.

I guess I need to re-cache the template?

How to solve this?

Thanks in advance.

Boofo
12-27-2011, 01:57 PM
Why don't you just use the parse_templates hook and do it in the mod itself? I know of no way to do it on the actual install procedure of a mod.

Lynne
12-27-2011, 04:41 PM
You don't want to actually change the master style. I think that would be a no-no.

Valter
12-28-2011, 08:11 AM
Thanks for you replies.

I've tried to do this in parse_templates but it won't work:
$vsa_tlmu_rstr_s = '<a class="title';
$vsa_tlmu_rstr_r = '<a style="{vb:raw thread.vsa_tlmu_css}" class="title';
$vbulletin->templatecache["threadbit"] = str_replace($vsa_tlmu_rstr_s, $vsa_tlmu_rstr_r, $vbulletin->templatecache["threadbit"]);


When I manually add
style="{vb:raw thread.vsa_tlmu_css}"
to the template, it works perfect.

thread.vsa_tlmu_css is produced in threadbit_process hook.

Boofo
12-28-2011, 08:45 AM
vb 4 does it differently. Try this in the parse_templates or process_templates_complete hook:

require_once(DIR . '/includes/class_template_parser.php');
$parser = new vB_TemplateParser('<a class="title');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$find = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$parser = new vB_TemplateParser('<a style="{vb:raw thread.vsa_tlmu_css}" class="title');
$parser->dom_doc = new vB_DomDocument($parser->fetch_dom_compatible());
$replace = trim($parser->_parse_nodes($parser->dom_doc->childNodes()));

$vbulletin->templatecache['threadbit'] = str_replace($find, $replace, $vbulletin->templatecache['threadbit']);
unset($find, $replace);

Valter
12-28-2011, 08:58 AM
Yes, it works.

You are genius. Thank You!

Edit: It also works when added after my code in threadbit_process.

Boofo
12-28-2011, 09:10 AM
You had doubts? ;)

And you are welcome, my friend.

Scanu
01-03-2012, 10:31 PM
thanks Boofo for your code it helped me too :)

Boofo
01-03-2012, 10:46 PM
I expect residuals. ;)