Get HTML output of template?


Active member
Is there an easy way to grab the rendered HTML output of a template of for example say "page_container_js_head". This would be outside the forums if it makes a difference. I've only done the bare basics initializing the XenForo app, but I'm a little clueless as to what to do next. Since the templates have params hopefully it's not too complicated to do.



Active member
Thank you Shadab, somehow I was not able to find that thread myself. Read most of the ones regarding templates except that one. :p Probably would have had better luck if I actually used the search here instead of googling...

Anyways, in my case, I need the $jQuerySource as a param, I had a look in the dependencies and saw it there, but it just states whether it is local or not. Do you know of a method to fetch the URL? I have another question, but I think I'll leave it for next time as it's getting a bit late here.

Before I forget, I wanted to thank you again, you are a great help in the development forums. :)


Well-known member
Thanks for the kind words. :)

I'll need to find a way to reuse the container parameters.
For now, you can grab the values for jQuerySource and jQuerySourceLocal from:
  • XenForo_Dependencies_Public::getJquerySource(), and
  • XenForo_Dependencies_Public::getJquerySource(true) respectively.


Well-known member
Found it. The dependency class has a getEffectiveContainerParams() method.
Haven't tried, but this should work:

// Your custom template parameters, if any
$viewParams = array(
	'foo' => 'bar'

// Merge the container parameters when rendering any non-content template
$params = $dependencies->getEffectiveContainerParams($viewParams, $request);

$content = $viewRenderer->renderView('', $params, 'page_container_js_head');


Active member
Templates that contain <xen:require /> don't seem to get the required js/css show up. And <!--XenForo_Require:JS--> is printed as a comment rather than replaced with the scripts. Any ideas about this one? Thanks.


Well-known member
Could you try this...

Instead of rendering the template directly via renderView(), grab a template object from the view renderer using createTemplateObject(). Render the template manually; and then pass the rendered contents + the template object to replaceRequiredExternalPlaceholders().

Basically, that's how renderContainer() works.
$template = $viewRenderer->createTemplateObject('your_template_name', $params);
$content = $viewRenderer->replaceRequiredExternalPlaceholders($template, $template->render());
But there's one catch. This won't work if you are building your page in a typical procedural style: header first, content second and footer last. That's because the external dependencies (css and js filenames) are not known until after you render the content templates. So you'll have to render the page chrome/container after you finish evaluating all the content templates; if you are not doing this already.