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

split_list_first and split_list_second smarty plugins

 
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 -> Plugins
View previous topic :: View next topic  

Include new plugins in smarty distribution?
Yes - useful and brings a new level of functionality to smarty
66%
 66%  [ 2 ]
No - quit dreaming. We have way better things to do.
33%
 33%  [ 1 ]
Total Votes : 3

Author Message
skky1142
Smarty n00b


Joined: 28 Sep 2007
Posts: 1

PostPosted: Fri Sep 28, 2007 2:10 pm    Post subject: split_list_first and split_list_second smarty plugins Reply with quote

Hello everyone,

I wrote two smarty plugins and would like some feedback on them.

You can find them in the wiki at: http://smarty.incutio.com/?page=split_list_first and at http://smarty.incutio.com/?page=split_list_second respectively.
I also included a poll.

Thanks,
Nick
Back to top
View user's profile Send private message
blackhawkmx
Smarty Regular


Joined: 20 May 2005
Posts: 76

PostPosted: Thu Dec 11, 2008 3:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
mitchenall
Smarty Pro


Joined: 27 Feb 2004
Posts: 107
Location: London, UK

PostPosted: Thu Dec 11, 2008 6:36 pm    Post subject: Reply with quote

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
View user's profile Send private message 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 -> Plugins 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