XF 2.1 Short conditional inside template (modification)

Scandal

Well-known member
Well, we have this part from template "forum_post_thread":
HTML:
<xf:submitrow submit="{{ phrase('post_thread') }}" icon="write" sticky="true">

I try to create a template modification to apply an "onclick" event on that submit button.

This is what I fill on the fields:
Search:
HTML:
icon="write"

Replace:
HTML:
$0 {{ ( $xf.request.filter('myvar', 'int') == 1 ? "onclick="alert('{{ phrase('phrase_name') }}');"" : '') }}

... but it returns syntax error.
I can't apply full conditional <xf:if> cause <xf:submitrow> is not allow inside it. I could apply as "Search" the whole submitrow field and then use <xf:if>, but I don't want too so it can be more compatible with future xF versions.

I suppose that the issue is on the " and ' characters but don't know how to fix it. I tried too some escape \ characters with no result.

Any idea?
 
In XF, there are other facilities to apply click handlers to elements (namely XF.Event JS handlers). Nevertheless, you can make this work using the replacement:

HTML:
$0 onclick="{{ $xf.request.filter('myvar', 'int') == 1 ? 'alert(\'' . phrase('phrase_name') . '\');' : '' }}"

You generally want to put conditionals inside attributes, you have to escape nested quotes, and you should use concatenation instead of nesting {{ ... }} expressions.
 
Back
Top Bottom