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

how do i use a var inside the {xen:phrase} tag as part of the phrase name?

Mutt

Well-known member
#1
I would like to call a phrase using a variable like this

Code:
{xen:phrase smiliecat_$smilie.category}
the var will always be an integer so I have phrases names smiliecat_0, smiliecat_1, smiliecat_2 that i'd like to grab.

but it's not seeing the value of the var. I tried wrapping $smilie.category w/ curly brackets or xen:raw curly brackets but neither worked.

anyone have a suggestion?
 

Bob

Well-known member
#2
unless something has changed, dynamic phrasing in templates is not allowed; since the phrase name needs to be known at compile time.
 

Mutt

Well-known member
#3
thanks bobster. that makes sense. I suppose I could do this
Code:
            <xen:if is="{$smilie.category} == 1">
                {xen:phrase smiliecat_1}
            <xen:elseif is="{$smilie.category} == 2" />
                {xen:phrase smiliecat_2}
            <xen:elseif is="{$smilie.category} == 3" />
                {xen:phrase smiliecat_3}
            <xen:elseif is="{$smilie.category} == 4" />
                {xen:phrase smiliecat_4}
            <xen:elseif is="{$smilie.category} == 5" />
                {xen:phrase smiliecat_5}
            <xen:elseif is="{$smilie.category} == 6" />
                {xen:phrase smiliecat_6}
            <xen:elseif is="{$smilie.category} == 7" />
                {xen:phrase smiliecat_7}
            <xen:elseif is="{$smilie.category} == 8" />
                {xen:phrase smiliecat_8}
            <xen:elseif is="{$smilie.category} == 9" />
                {xen:phrase smiliecat_9}
            <xen:else />
                {xen:phrase smiliecat_0}
            </xen:if>
that just seemed so long & messy
 
S

Syndol

Guest
#4
You could create the phrase in the php file, add it to the template params, and then just display it in the template.
In php use:
$phrase = new XenForo_Phrase('smiliecat_' . $smilie['category']);
then in the template call:
{$phrase}
 

Bob

Well-known member
#5
You could create the phrase in the php file, add it to the template params, and then just display it in the template.
In php use:
$phrase = new XenForo_Phrase('smiliecat_' . $smilie['category']);
then in the template call:
{$phrase}
thats pretty much the best way IMO.
 

xfrocks

Well-known member
#6
The reason you can't do that is: XenForo fetches the phrases and puts them in the parsed template. You will get best performance. If you use the XenForo_Phrase class, it will add one more query for the page unless the phrase is cached globally, also, you may want to use {xen:raw $phrase} because phrase can contain HTML