PDA

View Full Version : [How to] include a code within templates using a plugin or from another template


Infoman4ever
12-19-2011, 02:29 PM
Hi,
I know now how to create a plugin and link it to a hook, and how to create a template and put it "manually" on an existing template, but what I don't know yet is how to put a piece of code from a plugin or from a template "created manually" on a specific place within an existing template such as the posbit, posbit_legacy, showthread and so on. I need to do it to create a general product, right?
Well, I tried using hooks, but sometimes they do not help, they do not cover some places within some templates.
Any help will be highly appreciated.

kh99
12-20-2011, 01:17 PM
I was hoping someone else could answer who might be able to explain better, but...

You need to do a str_replace() (or equivalent) on $vbulletin->templatecache['template_name'], and it has to be at a hook location where the templates have been cached but not rendered yet. Location parse_templates should work. Also, you need to look at the compiled template to see what you can match as the "needle" in str_replace(). It may or may not be the same as you see when you look at the template in the template editor. To see the compiled template, look in the "template" table of the database in the "template" column, or print out the value of $vbulletin->templatecache['template_name'].

So when you've done all that your code could look something like:

$find = "some html string";
$replace = "some other html string";
$vbulletin->templatecache['template_name'] = str_replace($find, $replace, $vbulletin->templatecache['template_name']);


Note that most compiled templates are actually php code that produces the template html when eval'd, so you could also insert php code into the template is you wanted.

Infoman4ever
12-21-2011, 04:50 PM
Great! that what I was looking for, thanks.