Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Writing a tricky if condition within a {foreach} loop

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
singhkarki
Smarty n00b


Joined: 15 Oct 2014
Posts: 1

PostPosted: Wed Oct 15, 2014 5:13 am    Post subject: Writing a tricky if condition within a {foreach} loop Reply with quote

hello team , hope you guys are doing great
I have an if condition within a {foreach} loop ,
the snippet of the web page where it works is as follows :
................................................
Field Value
................................................
Identifier http://abc.com

Now the job starts where value starts taking numeric ip addresses as follows:
................................................
Field Value
................................................
Identifier http://192.168.8.158:80/cgi-bin/koha/opac-detail.pl?biblionumber=2

The code snippet below is to be rewritten satisfying the condition that whenever the value of above is numeric private ip address the <a href should be $vij otherwise it has to remain $value.

{ foreach from=$entry item=value}
{if $name ==ídentifier'}
<a href="{$value|escape}">{$value|escape|default:"&mdash;"}</a>
{else}
{$value|trim|nl2br|strip_unsafe_html|default:"$mdash;"}
{/if}<br/>
{/foreach}



writing an if condition in above with the simple spec
if $value begins with the pattern http://192.168.
<a href="{$vij|escape}">{$value|escape|default:"&mdash;"}</a>
{else}
{$value|trim|nl2br|strip_unsafe_html|default:"$mdash;"}
{/if}<br/>
{/foreach}


What i have did was , it didn't work though

{assign var="vij" value="http://abc.res.in/record_opac.php"}
{assign var="replacement" value="http://abc.res.in/record_opac.php"}
{assign var="pattern" value="http://192.168.8."}
{assign var="string" value="$value"}
{php}

preg_replace($pattern , $replacement ,$string)
{/php}


Your reply will be a great help ,

thanks and best regards,

immortalveejay
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP