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

Templates : dynamic include

allewreK

Active member
#1
Hello,

I would like to dynamicly include a template :
Code:
<xen:include template="$myTemplate" />
It's not allowing me to save the template, any way to do it ?

Kind regards,
:)
 

Chris D

XenForo developer
Staff member
#2
Unlikely to be possible. After you hit save the template is compiled and the included template is compiled in to it. Therefore the compiler would need to know the value of $myTemplate which, presumably at that point, it doesn't.
 

Chris D

XenForo developer
Staff member
#5
In theory, you can do this in the view.

I'm not sure why it needs to be dynamic, or under what conditions it needs to be dynamic... but the view would be the place to do this:

PHP:
$this->_params['someHtml'] = $this->_renderer->createTemplateObject($aDynamicTemplateName, $params);
You can then use that in your template:

HTML:
{xen:raw $someHtml}
In conjunction with this, you may want to pre load your template with the template_create event listener.
 

allewreK

Active member
#6
In theory, you can do this in the view.

I'm not sure why it needs to be dynamic, or under what conditions it needs to be dynamic... but the view would be the place to do this:

PHP:
$this->_params['someHtml'] = $this->_renderer->createTemplateObject($aDynamicTemplateName, $params);
You can then use that in your template:

HTML:
{xen:raw $someHtml}
In conjunction with this, you may want to pre load your template with the template_create event listener.
You rock as always Chris, I don't need more thanks you very much that will do the job!! :)