XF 2.2 From var to phrase?


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


in template with

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

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

<xf:macro name="privacy_option"
                    arg-label="{{ phrase('r9_allow_view_profile:') }}" />

<xf:macro name="privacy_option" arg-name="!" arg-label="!" >
    <dl class="pairs pairs--columns pairs--fixedSmall">
                <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') }}
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