<xen:container var

Chris D

XenForo developer
Staff member
I think I'm overlooking something.

I would like to set a variable in a template, and have it available to use in the PAGE_CONTAINER. This is usually done like this:

Code:
<xen:container var="$head.canonical"><link rel="canonical" href="{xen:link 'canonical:index'}" /></xen:container>

Then in the PAGE_CONTAINER template, the {$head} variable is available.

I'd like to do something similar, e.g.

Code:
<xen:container var="$foo.bar">1</xen:container>

But when I do, in PAGE_CONTAINER:

Code:
{xen:helper dump, $foo}

The value returned is NULL.

So clearly I'm missing something, but I can't think what.
 
You need to set your var first.

Code:
<xen:set var="$foo"></xen:set>

<xen:container var="$foo">bar</xen:container>
 
That still doesn't work, unfortunately.

<xen:container var="" should be setting the contents of the var to be used in the container. But again either way, it is still NULL.
 
Update.

Courtesy of @Jake Bunce problem is my template where I was defining the container var is actually contained in the container template already.

This works fine if I use the <xen:container tags in content template or templates included by the content template.
 
Update.

Courtesy of @Jake Bunce problem is my template where I was defining the container var is actually contained in the container template already.

This works fine if I use the <xen:container tags in content template or templates included by the content template.
Resurrecting an old thread...I'm having the same/similar issue where I perform a '<xen:container var...' in a template, and I do have the ability to access the var in PAGE_CONTAINER, but my goal is to show it in a different template (message_user_info). Am I missing how to pass the var from template to template? In particular, into message_user_info.
 
Last edited:
If your variable is available in a parent template it is usually also available in any included templates. One exception is macros, which have their own namespace unless declared global. You'll need to pipe your extra variable into those macros as additional argument and edit the macro to accept said argument.
 
If your variable is available in a parent template it is usually also available in any included templates. One exception is macros, which have their own namespace unless declared global. You'll need to pipe your extra variable into those macros as additional argument and edit the macro to accept said argument.
I've been really struggling with this, so would appreciate a hand holding. Here's what I have:

  • template A contains the variable I'd like to use in template message_user_info
  • using a <xen:container var="$foo" in template A, I can access $foo in PAGE_CONTAINER, but not in message_user_info (nor in thread_view, as an alternate test)
When we're referring to a "parent template", wouldn't message_user_info (and thread_view) be considered children of PAGE_CONTAINER?
 
No. Page container is an entirely separate story. If your variable is available in thread view, you'll likely need to forward it to the post macro, from there to the message macro and from there to the message user info macro. I don't have the code at hand at the moment, so I can't be more specific. Search the macros that call the respective code snippets and forward your info as additional parameter to it.
 
No. Page container is an entirely separate story. If your variable is available in thread view, you'll likely need to forward it to the post macro, from there to the message macro and from there to the message user info macro. I don't have the code at hand at the moment, so I can't be more specific. Search the macros that call the respective code snippets and forward your info as additional parameter to it.
I'm unfamiliar with the use of macros...is this something available in xf1? I'm yet to upgrade due to the reworking of custom add-ons, but am seeing xf2 documentation on it--

Is there an equivalent in xf1? I'm really banging my head against the wall on how to successfully pass a var along from template to template.

Again, I appreciate your help. Been running in circles on this.
 
Oh, my bad. I wasn't paying attention to that. There's no macros in xf1. To pass variables down the template chain I believe you had to place them inside the include statement.
 
Oh, my bad. I wasn't paying attention to that. There's no macros in xf1. To pass variables down the template chain I believe you had to place them inside the include statement.
:) no worries -- this is helpful. Hopefully last clarifying question: when referring to placing the variables inside an include statement, are you referring to a <xen:include template w/in ACP? I'm not aware of how to explicitly pass along a specified var within that statement, unless all vars are inherently passed along when performing a include template?

--Or are you referring to this having to be handled via an add-on/php (which I know very little about)?
 
Top Bottom