1. 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?

Discussion in 'Styling and Customization Questions' started by Mutt, Feb 25, 2012.

  1. Mutt

    Mutt Well-Known Member

    I would like to call a phrase using a variable like this

    {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?
  2. Bob

    Bob Well-Known Member

    unless something has changed, dynamic phrasing in templates is not allowed; since the phrase name needs to be known at compile time.
  3. Mutt

    Mutt Well-Known Member

    thanks bobster. that makes sense. I suppose I could do this
                <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}
    that just seemed so long & messy
  4. Syndol

    Syndol Guest

    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:
    Sean Kendle likes this.
  5. Bob

    Bob Well-Known Member

    thats pretty much the best way IMO.
  6. xfrocks

    xfrocks Well-Known Member

    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

Share This Page