XF 2.3 Javascript phrase parameters

stromb0li

Well-known member
I'm trying to display a phrase via javascript (that takes a parameter), but I don't see the substituted value:

my_phrase has the following in my phrases.xml file: '{myParam} man'

XF.phrase("my_phrase",{"{myParam}":'weeee'})

Unfortunately, I only see my_phrase rendered on the page.

If I add this to my template, then everything works, but is it necessary to redefine the phrase in the template as well?
HTML:
<xf:js>
     XF.extendObject(XF.phrases,
        {
            myParam: "{{phrase('my_phrase')}}"
        }
</xf:js>
 
Last edited:
Phrases are rendered server side and shipping them all to the client would be a bad idea, so yes you must declare them in JS manually. The second parameter takes a dictionary of keys and values, the same as PHP.

HTML:
<xf:js>
    XF.extendObject(XF.phrases,
    {
        some_phrase: "{{ phrase('some_phrase')|escape('js') }}",
    });
</xf:js>

JavaScript:
XF.phrase('some_phrase', {some_param: 'some_value'})
 
Back
Top Bottom