I have a problem with smarty framework, so I need to verify if an image name starts with 'http': I try this code:
{foreach from=$video->result() item=v}
{if substr($v->image,0,4) eq 'http'}
<img src="{$v->image}" alt="">
{else}
<img src="{$IMG_URL}videos/images/{$v->date|date_format:'%Y'}/{$v->date|date_format:'%m'}/{$v->image}" alt="">
{/if}
{/foreach}
Help me please..Exists another way?
This code should work fine. Probably your data is not set properly.
Consider the following testing code:
PHP file:
class V {
public $image = 'http://rwewreuiuiwre';
}
$smarty->assign('v', new V());
Template file:
{if substr($v->image,0,4) eq 'http'}
http
{else}
non http
{/if}
It works fine. If you change $image to hxttp you get non http
message