Hello everyone, please help with smarty template engine. How to check if {% $ image.value%} contains "https" at the beginning of the name, then output it in this format

<li class="gallery-img-wrapper" data-thumb="{%$image.value%}" data-src="{%$image.value%}"> 

if not then

  <li class="gallery-img-wrapper" data-thumb="{%$settings.patch%}uploads/images/ts/{%$image.value%}" data-src="{%$settings.patch%}uploads/images/tb/{%$image.value%}"> 

    1 answer 1

     {if strlen($image.value) > 4} {if substr($image.value, 0, 5) == 'https'} ТУТ ВЫВОД ДЛЯ HTTPS {else} ТУТ ВЫВОД ДЛЯ HTTP {/if} {else} // image.value имеет малую длину {/if} 

    Yab would have shoved a lot of things out of checks, but I think the meaning is clear, and then you will figure it out further.

    Ps1. Ideally, this option would be correct, try it if it works:

     {if strtolower(substr($image.value, 0, 5)) == 'https'} 

    PS2. If you are not sure what encodings will be there, then: mb_strlen , mb_strtolower and mb_substr .

    PS3. If you are sure that the string always contains a URL, then the first condition can be deleted.

    • one
      {if $image.value|strlen > 4} or {$imag.value|substr:0:5} this is more like smarty templates. - teran