RE: [SMARTY] indirect indexing (was: nested foreach loop)
| From: | Robert V. Zwink | Date: | Thu, 11 Apr 2002 17:07:33 +0000 |
| Subject: | RE: [SMARTY] indirect indexing (was: nested foreach loop) | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-3634@lists.php.net to get a copy of this message | ||
Thanks for your quick response. When you say "...and I now added ability to
index arrays and access object properties indirectly via simple variables"
does this mean you have added it to CVS somewhere, or you added to
specifications that will be implemented for the next version?
We've had great results with a Smarty/Zend Accelerator versus
FastTemplate/Zend Accelerator benchmark. Thanks to Smarty I'm going to have
to work late all week re-writing our FastTemplate site :) Thanks!?!
I also have another question. In the manual on page
http://www.phpinsider.com/php/code/Smarty/docs/tips.html#TIPS.BLANK.VAR.HAND
LING
I see the example:
{* the short way *}
{$title|default:" "}
This doesn't seem to work for me. I get the error:
Warning: Smarty plugin error: [in smarty_single_product_results.ptpl line
136]: modifier 'default' is not implemented in
/m1/web/devmccom/php-lib/classes/Smarty.class.php on line 1647
Am I missing something? I have Smarty Version: 2.0.1 recently downloaded
from phpinsider.com and PHP Version 4.0.6
Thanks!
Robert v. Zwink
http://www.zwink.net/daid.php
-----Original Message-----
From: Andrei Zmievski [mailto:andrei@ispi.net]
Sent: Thursday, April 11, 2002 12:27 PM
To: Robert V. Zwink
Cc: smarty-general@lists.php.net
Subject: Re: [SMARTY] indirect indexing (was: nested foreach loop)
On Thu, 11 Apr 2002, Robert V. Zwink wrote:
> The idea is that I have two arrays, one array contains a list of
categories,
> the other array contains a list of subcategories. The category array is
> setup like this
> array("3digitID"=>"title")
>
> and the subcategory array is setup like this
> array("3digitID"=>array("4digitID"=>"title"))
>
> This way I can use Smarty to traverse the category array, then compare the
> current 3digitID to the first element in subcategory array, and display
the
> subcategories. Its seems like I could by pass the {if} conditional if it
> were possible to specify which element of a multidimensional array to
> foreach.
>
> My question is how do I specify an element of a multidimensional array to
> foreach? I want to be able to do something like this:
>
> {foreach name=subcategories_left item=subcategory
> key=subcat_coordinate_group from=$subcategories_left[$other_foreach_var]}
>
> Where $other_foreach_var == the "key" from the current parent foreach, and
> $subcategories_left is a multidimensional array.
Hi,
This has been discussed in the past, but what stopped it from going
forward is the difficult of parsing recursive variable references using
regular expressions. However, your post served as a tipping point, and I
now added ability to index arrays and access object properties
indirectly via simple variables. Example:
/* php script */
$tpl->assign("level1" => array("123" => "one-two-three",
"456" => "four-five-six"));
$tpl->assign("level2" => "123");
$tpl->assign("complex" => "123456");
{* template *}
word: {$level1.$level2}
{* or even *}
{assign var="simple" value=$complex|truncate:3:"":yes}
word: {$level1.$simple}
Note that you can't use modifiers or index the indexing variable itself.
It has to be a simple template variable. If you want something more
complicated, use {assign} as shown above.
-Andrei
"You choose to do the bad things in your life;
the good ones come and drag you along with them."
- Michael Marshall Smith
--
Smarty General Mailing List (http://smarty.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php