|
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 |
lusid Smarty n00b
Joined: 01 Aug 2004 Posts: 4 Location: Miami, FL
|
Posted: Fri Nov 26, 2004 8:09 am Post subject: Smarty code within a block function? |
|
|
If I create a block function, and the template designer passes Smarty commands inside the block, is there something special I have to do to compile them (or what not) before returning the new output? Or should I just return the output with Smarty code included, and Smarty will parse it further as needed?
Basically, I want to do something similar to the section block that's built-in... you can do nested sections, and it works. Any way to create a custom block that will have this same functionality?
Thanks,
Marc |
|
Back to top |
|
lusid Smarty n00b
Joined: 01 Aug 2004 Posts: 4 Location: Miami, FL
|
Posted: Fri Nov 26, 2004 8:23 am Post subject: |
|
|
Actually, here's a better example of what I'm trying to do on the template side:
Code: | {foreach from=myarray item=myitem assign=newarray}
Hello {$myitem.name}, you are from {$myitem.city}.
{/foreach} |
You'll notice that I'm using an "assign" parameter here, which isn't really part of the Smarty function, foreach. But essentially, I need something that does the same thing as foreach, but has the ability to take the content (between the foreach tags) and store it into an array with the same number of elements as the inputted "from" parameter... this is how this would look in PHP, for example:
Code: | function simplify_array($from) {
global $smarty;
$tmp = array();
foreach ($myarray as $v) {
array_push($tmp, "Hello $v[name], you are from $v[city].");
}
$smarty->assign($assign, $tmp);
} |
But I need the content to be completely customizable by the template designer, so if they wanted to display "You are from $v[city], aren't you $v[name]?" (in Smarty, this would be "You are from {$myitem.city}, aren't you {$myitem.name}?"), they could without touching any PHP code.
Any suggestions? |
|
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
|