Smarty: Assigning custom function section variable
| From: | Alexander Skwar | Date: | Sun, 19 Aug 2001 11:18:29 +0000 |
| Subject: | Smarty: Assigning custom function section variable | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-63385@lists.php.net to get a copy of this message | ||
Hi!
I'm having some problem assigning a custom function ({math}) a value of
a {section} block.
I've got a section where I want to do some easy math. But somehow I'm
stuck....
Here's my template:
<html><head><title>Section Test</title></title></head><body
bgcolor=white>
{section name=people loop=$FirstName}
{$FirstName[people]} {$LastName[people]}
{math equation="x + y" x="{$FirstName[people]}"
y="{$LastName[people]}"}<br>
{/section}
</body></html>
The PHP code:
<?php
require_once 'Smarty.class.php';
$smarty = new Smarty();
$x = array(1, 2, 3, 4, 5);
$y = array(9, 8, 7, 6, 5);
$smarty->assign("FirstName", $y);
$smarty->assign("LastName", $x);
$smarty->display("test.tpl");
?>
When I run this, I get the following errormessage in my browser:
Parse error: parse error, expecting `'}'' in
/home/askwar/public_html/olg/html/templates_c/test.tpl.php on line 65
Line 65:
<?php smarty_func_math(array('equation' => "x + y",'x' =>
"{$FirstName[people]"), $this); if($this->_extract) {
extract($this->_tpl_vars); $this->_extract=false; } ?>" y="<?php echo
$this->_tpl_vars['LastName'][$this->_sections['people']['properties']['index']]
;?>
Also removing the { and } at the x= and y= section in my template
doesn't work. The section now looks like this:
{section name=people loop=$FirstName}
{%people.rownum%} {$FirstName[people]} {$LastName[people]} {math
equation="x + y" x="$FirstName[people]"
y="$LastName[people]"}<br>
{/section}
Now I get 5 lines in my browser, but also a different error message:
1 9 1
Warning: Smarty error: math: parameter x is empty in
/home/askwar/public_html/olg/html/OliG-System/smarty/Smarty.class.php on
line 1090
The first "1 9 1" is correct. It's the row number and the values of x
and y.
How can I do this?
Thanks a lot!
Alexander Skwar
--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.digitalprojects.com | http://www.iso-top.de
iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 1 day 12 hours 10 minutes