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

Templates : dynamic include

Discussion in 'XenForo Development Discussions' started by allewreK, Jun 19, 2014.

  1. allewreK

    allewreK Active Member


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

    Kind regards,
  2. Chris D

    Chris D XenForo Developer Staff Member

    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.
  3. allewreK

    allewreK Active Member

    Ok thanks you very much Chris, I'm going to find an alternative.
  4. allewreK

    allewreK Active Member

    That sucks in fact, can't do an alternative.
  5. Chris D

    Chris D XenForo Developer Staff Member

    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:

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

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

    allewreK Active Member

    You rock as always Chris, I don't need more thanks you very much that will do the job!! :)
    Chris D likes this.

Share This Page