|
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 |
Include new plugins in smarty distribution? |
Yes - useful and brings a new level of functionality to smarty |
|
66% |
[ 2 ] |
No - quit dreaming. We have way better things to do. |
|
33% |
[ 1 ] |
|
Total Votes : 3 |
|
Author |
Message |
skky1142 Smarty n00b
Joined: 28 Sep 2007 Posts: 1
|
|
Back to top |
|
blackhawkmx Smarty Regular
Joined: 20 May 2005 Posts: 76
|
Posted: Thu Dec 11, 2008 3:23 pm Post subject: |
|
|
Hi Nick,
is there any way we can return all parts of the string, not just the first or the last part. for example I will have
one@two@three@four
and want to return
one
two
three
four
I'm testing a condition to get an exact match for a value inside a long string after its broken up by commas ","
thanks!
-bh _________________ Bring it back to basics. You and I can make it right! |
|
Back to top |
|
mitchenall Smarty Pro
Joined: 27 Feb 2004 Posts: 107 Location: London, UK
|
Posted: Thu Dec 11, 2008 6:36 pm Post subject: |
|
|
blackhawkmx wrote: | Hi Nick,
is there any way we can return all parts of the string, not just the first or the last part. for example I will have
one@two@three@four
and want to return
one
two
three
four
|
You don't even need a plugin for that. Just use the PHP explode() function as a modifier along with a foreach, e.g.
Code: |
{foreach from='@'|explode:'one@two@three@four' item=word}
{$word}<br />
{/foreach}
|
or for a comma separated list...
Code: |
{foreach from=','|explode:'one,two,three,four' item=word}
{$word}<br />
{/foreach}
|
In fact, the two above plug-ins could be replaced by something similar, e.g.
Code: |
{assign var=parts value='@'|explode:'mailbox@domain.com'}
Mailbox: {$parts.0}
Domain: {$parts.1}
|
To be honest, though, this is something I'd do in PHP and pass to the template as an array, or at least pass an object which has a method call which returns the array I need for the view. Using modifiers works fine, but does necessarily read well in these situations. |
|
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
|