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

Building a Varible then Printing?

 
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
Nick W
Smarty Rookie


Joined: 23 May 2003
Posts: 22

PostPosted: Mon Oct 20, 2003 3:51 pm    Post subject: Building a Varible then Printing? Reply with quote

Hi all,

In this thread I failed miserably despite help to get regex_replace working with arrays: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=1214

So, I'm working at it for another angle:

Code:

                {foreach from=$searchreplace key=key item=item}
                {$cmts.Comment|regex_replace:$key:$item}
                {/foreach}


(whre $searchreplace is just somthing like this

array("/search/" => "replace");

You can see the problem right? - It prints the comment each time.

Is there a way to build a varible in that loop then output it instead of what I'm doing?

Many thanks..

Nick
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Oct 20, 2003 5:14 pm    Post subject: Reply with quote

i'd write my own little modifier:

(untested)
[php:1:c6ac8a9493]
function smarty_modifier_search_replace($var, $exprs) {
return preg_replace(array_keys($exprs), array_values($exprs), $var);
}
[/php:1:c6ac8a9493]

HTH
Back to top
View user's profile Send private message Send e-mail Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Mon Oct 20, 2003 9:08 pm    Post subject: Reply with quote

actually, I'd do the data scrubbing in PHP, not in template Smile

But I think you want:
Code:
{assign var=process value=$cmts.Comment}
{foreach from=$searchreplace key=key item=item}
    {assign var=process value=$process|regex_replace:$key:$item}
{/foreach}
{$process}

Which is obviously not as nice as messju's custom plugin suggestion Smile
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Mon Oct 20, 2003 9:13 pm    Post subject: Reply with quote

boots wrote:
actually, I'd do the data scrubbing in PHP, not in template Smile

me too Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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