XF 2.2 xf:if in a template modification

Anatoliy

Well-known member
I'm creating an addon that serves responsive images using a third part service. So I added a template modification to lightbox_macros and it works.

Code:
        <img src="{$src}"
            data-url="{$dataUrl}"
            class="bbImage"
            data-zoom-target="1"
            style="{$styleAttr}"
            alt="{$alt|for_attr}"
            title="{$title|for_attr}"
            width="{$width}" height="{$height}" loading="lazy" />

replace:

Code:
        <img src="https://thirdpartydomain/{$src|replace({'https://www.mydomain/':null})}"
            data-url="{$dataUrl}"
            class="bbImage"
            data-zoom-target="1"
            style="{$styleAttr}"
            alt="{$alt|for_attr}"
            title="{$title|for_attr}" loading="lazy" />

However pictures that are displayed with "proxy.php" are broken. So I decided that a solution would be a conditional, but it doesn't work. Pease advice.

Code:
<xf:if is="{{strstr($src, 'proxy.php')}}">
    $0
    <xf:else />
        <img src="https://thirdpartydomain/{$src|replace({'https://www.mydomain//':null})}"
            data-url="{$dataUrl}"
            class="bbImage"
            data-zoom-target="1"
            style="{$styleAttr}"
            alt="{$alt|for_attr}"
            title="{$title|for_attr}" loading="lazy" />   
</xf:if>
 
I tried also str_contains, I tried to search for 'proxy' instead of 'proxy.php', but it doesn't recognize proxied images.
I guess a problem not with php functions, but with some error in my code.
Please help.
 
I'm stuck completely... How come
<xf:if is="{{strlen($post.message) > 100}}"> works, but
<xf:if is="{{str_contains($src, 'proxy.php')}}"> doesn't?

TestyWigglyArachnid-size_restricted.gif
 
{{ }} is not a wrapper for arbitrary php code, it only supports a limited set of functions. It should've given you a relevant error to indicate that.

You can see the full list in XF\Template\Templater. I'm pretty sure strpos() !== null is supported.
 
{{ }} is not a wrapper for arbitrary php code, it only supports a limited set of functions. It should've given you a relevant error to indicate that.

You can see the full list in XF\Template\Templater. I'm pretty sure strpos() !== null is supported.
It works! Thank you!!!
 
Top Bottom