• 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

R

ragtek

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

Then i tried:
PHP:
<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?
 

James

Well-known member
#2
I'm not sure if it's strictly needed, but isn't the <xen:include> meant to be self-closing?
Code:
<xen:include template="my_template" />
 

James

Well-known member
#4
I've tried to include a template with this code:
PHP:
<xen:include template="{$messagetamplate}">
but it's not working.

Then i tried:
PHP:
<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?
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)
 

Kier

XenForo Developer
Staff member
#5
Code:
<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.
Code:
<xen:if is="{$foo}">
	<xen:include template="t1" />
<xen:else />
	<xen:include template="t2" />
</xen:if>
That will work fine. We do it within the post template.