|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Nick W Smarty Rookie
Joined: 23 May 2003 Posts: 22
|
Posted: Mon Oct 20, 2003 3:51 pm Post subject: Building a Varible then Printing? |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Oct 20, 2003 5:14 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Oct 20, 2003 9:08 pm Post subject: |
|
|
actually, I'd do the data scrubbing in PHP, not in template
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 |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Mon Oct 20, 2003 9:13 pm Post subject: |
|
|
boots wrote: | actually, I'd do the data scrubbing in PHP, not in template |
me too |
|
Back to top |
|
|
|
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
|