XF 2.2 From var to phrase?

Robert9

Well-known member
What is the best way to come from a var with value "everybody, members, followed, none" to a phrase, please?

{{$user.Privacy.allow_send_personal_conversation}}

in template with

if $x = 'everybody' => phrase('everbody')
else ...

or better translate it before passed to the template?
 
Solved with something like:

Code:
<xf:macro name="privacy_option"
                    arg-name="{{$user.Privacy.allow_view_profile}}"
                    arg-label="{{ phrase('r9_allow_view_profile:') }}" />


Code:
<xf:macro name="privacy_option" arg-name="!" arg-label="!" >
    <dl class="pairs pairs--columns pairs--fixedSmall">
        <dt>{$label}</dt>
        <dd>
                <xf:if is="$name=='everyone'">{{ phrase('all_visitors') }}
                <xf:elseif is="$name=='members'" />{{ phrase('members_only') }}
                <xf:elseif is="$name=='followed'" />{{ phrase('people_you_follow') }}
                <xf:else />{{ phrase('nobody') }}
                </xf:if>
        </dd>
    </dl>
</xf:macro>
 
Use the phrase_dynamic templater function to create a phrase from a string generated at runtime, or create a getter on your entity that loads the phrase, which you can then use in the template. Make sure to use a phrase group in either scenario, to not cause additional database queries when loading the phrase in.
 
Thank you. Have done it in an equal way like in the original xf-template for the privacy-page in account..
 
Top Bottom