include template with variable name

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
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?
 
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" />
 
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" />
not if you set variables for the template ;)
 
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)
 
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.
 
Top Bottom