[PATCH] Error in section propery handling
| From: | Ludovic LANGE | Date: | Sun, 13 May 2001 18:38:52 +0000 |
| Subject: | [PATCH] Error in section propery handling | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-753@lists.php.net to get a copy of this message | ||
Hello,
I think I've found a difference between the behaviour described in the documentation and the way Smarty-1.4.0 handles section properties.
In particular, according to the documentation example 5-26, we can use section properties ( <section name>.index_prev for example ) as indexes of a variable.
Here is the example from the documentation to illustrate my problems (look at the comment 'FYI', and the line just below ):
-------------------------------------------------------------
Example 5-26. section property index_prev
{section name=customer loop=$custid}
{%customer.index%} id: {$custid[customer]}<br>
{* FYI, $custid[customer.index] and $custid[customer] are identical in meaning *}
{if $custid[customer.index_prev] ne $custid[customer.index]}
The customer id changed<br>{/if} {/section} ------------------------------------------------------------- But the $custid[customer.index_prev] doesn't get compiled as it should by Smarty. Instead, it produces the following code : $this->_tpl_vars['custid']['index_prev'] where in fact it should produce : $this->_tpl_vars['custid'][$_smarty_sections['customer']['properties']['index_prev']] I think the problem is located in the function _parse_var in Smarty_Compiler.class.php, in the regular expression. I've done the following modification, which seems to work well. Please try and test it. (the line numbers in the diff may not be right, I've done other modifications.) (btw, I'm using PHP-4.0.4pl1. I've not tried this with 4.0.5)
--- Smarty-1.4.0/Smarty_Compiler.class.php Mon May 7 16:40:11 2001 +++ Smarty/Smarty_Compiler.class.php Sun May 13 20:24:35 2001@@ -724,7 +739,7 @@ {
list($var_ref, $modifiers) = explode('|', substr($var_expr, 1), 2);
- preg_match_all('!\[\w+\]|(->|\.)\w+|^\w+!', $var_ref, $match);
+ preg_match_all('!\[\w+(?:\.\w+)?\]|(->|\.)\w+|^\w+!', $var_ref,$match);
$indexes = $match[0];
$var_name = array_shift($indexes);
Best regards,
Ludovic LANGE