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

include template with variable name

Discussion in 'XenForo Development Discussions' started by ragtek, Jun 2, 2011.

  1. ragtek

    ragtek Guest

    I've tried to include a template with this code:
    <xen:include template="{$messagetamplate}">
    but it's not working.

    Then i tried:
    <xen:if is="$foo">
    xen:include template="1">
    xen:else />
    xen:include template="2">
    but that's also not working.

    A way would be to create a exact copy of my template and just to change the template name, but that's against DRY :D
    Is there a other way for this?
  2. James

    James Well-Known Member

    I'm not sure if it's strictly needed, but isn't the <xen:include> meant to be self-closing?
    <xen:include template="my_template" />
  3. ragtek

    ragtek Guest

    not if you set variables for the template ;)
  4. James

    James Well-Known Member

    Are you trying to include the template via a variable? i.e.:
    <xen:set var="$mytemplate">mytemplate</xen>

    If so, have you tried using {xen:raw}?
    <xen:include template="{xen:raw $messagetemplate}">

    (Just grasping at straws here, you've probably tried it already)
  5. Kier

    Kier XenForo Developer Staff Member

    <xen:include template="{$templateName}" />
    You can never do that. Template inclusion is handled at template compilation time, it would never see that variable. The only way to do what you want is within a custom View.
    <xen:if is="{$foo}">
    	<xen:include template="t1" />
    <xen:else />
    	<xen:include template="t2" />
    That will work fine. We do it within the post template.
    Scarface, xenTheory and Fuhrmann like this.

Share This Page