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

How to implode() an array within the template?

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
bimal
Smarty Elite


Joined: 19 Apr 2007
Posts: 423

PostPosted: Tue Oct 20, 2009 11:12 am    Post subject: How to implode() an array within the template? Reply with quote

The below example explains how you can use the implode() function within the template, for an assigned array.

For example, see, how the $smarty_hints looks like in php, first:
Code:
Array
(
    [0] => <span class="search">DSCN26490</span>
    [1] => <span class="search">Newly arrived bags</span>
    [2] => <span class="search">Backpack</span>
    [3] => <span class="search">Ghau</span>
    [4] => <span class="search">Tsampa bowl</span>
    [5] => <span class="search">resin statue</span>
)


You assigned it to Smarty with something like:
Code:
$smarty->assign('search_hints', $search_hints);

Or, the variable can come as a dynamic portion of {assign ... } within the template. Now, the below script will implode it, separating each of the entries with a comma ( , ).
Code:
<div style="font-size:10px;">
   <strong>Examples</strong>:
   {', '|implode:$search_hints}
</div>


The glue string - comma ( , ) - is given first, to a modifier: implode. We do not need to define how it should work, as this is a callable function from PHP itself. And, the second parameter is the array name, that we passed after the colon ( : ), and it works.

Let me know, if you enjoyed this.
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 -> Tips and Tricks 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