• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Event Listener Editor: how to make a "Template_PRE_render" ?


Well-known member
Sorry I'm note yet familiar with xF terminology, but is it possible to modify a template (without hook) BEFORE it is rendered. If I understood correctly:

  1. "Template_post_render" is similar to vB "parse_templates" hook
  2. "Template_create" is a way to cache template. I first thought it was similar to vB "cache_templates" hook, but it seems there's no way to access $content variable from here.
  3. "Template_hook" is used to modify the template before it is rendered but only between hooks.
For example I'm trying to do a simple thing : copy a template code into another template, using a regex to modify some elements. Very simple to do with vB3 ; but with xF I still don't understand how to do it. Spending hours without any success is quite discouraging :cry:


Well-known member
Thank you for your answers. That's not really what I was looking for, but my question wasn't really correct.

I've just discovered that the "Template_hook" node also allow to made modifications on templates without hook yet. You just need to use a parent template which has a hook For example, the template "node_category_level_1" doesn't have any hook inside. But it still can be modified with the "Template_hook" node using the hook "page_container_head" of its parent template "PAGE_CONTAINER". Then a simple search and replace (str/regex) will work. But it still remains a little problem.

I can search any element of the template code, except the one using the xen format code, ie: "<xen:if is="{$renderedChildren}">". In vBulletin 3, I just capture the template raw code using "print_r" or having a quick look in the database (ie, for the "if" elements), but neither of these methods work with xenForo.

I just wonder if it's possible.

Edit: I forgot, for those who would like to find which template hook can be the one of the parent template they're looking for, just put in their listener a simple :
echo "$hookName <br />";


Well-known member
You can't do similar search and replace technique with $vbulletin->templatecache in XenForo because XenForo templates are completely "transformed" once they are compiled. You can take a look into xf_template_compiled and you will understand what I said. Because of that, even if you have template_pre_render, you can't do anything much.

So, to put your contents into the template, you should use template_hook or you can use template_post_render and... do a search and replace. With tricky positions, I recommend using jQuery.xfInsert instead ;)