Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Why "math" doesn't work?

 
Post new topic   Reply to topic    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
4Axis
Smarty n00b


Joined: 01 Sep 2015
Posts: 2

PostPosted: Tue Sep 01, 2015 8:23 am    Post subject: Why "math" doesn't work? Reply with quote

Hi.
I would like to multiply the variables in the TPL.
But, unfortunately, does not work and do not know why.
Code:

{assign var="name" value=$product['name']|substr:-15}
{assign var="pos" value=$name|regex_replace:"/[\D]/":""}
{assign var="alla" value=$product['quantity']}
{$product['quantity']} --- {$pos} --- {$alla}
{math assign="span" equation="x * y" x=(int)$pos y=(int)$alla}
{$span}


Clean $ pos = 50 and $ alla = 1, (int) $ pos = 50 and (int) $ alla = 0.
If I try math without (int) is nothing shows.
Please help
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1568

PostPosted: Tue Sep 01, 2015 8:53 am    Post subject: Reply with quote

Code:
<?php

require_once 'smarty-config.php';

$template = <<<'SMARTY_TEMPLATE'
{$x*$y}
SMARTY_TEMPLATE;

$tpl->assign(array('x' => 2, 'y' => 3));
$tpl->display("string:$template");
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7366
Location: Lincoln Nebraska, USA

PostPosted: Wed Sep 02, 2015 1:57 am    Post subject: Reply with quote

what version of Smarty are you using? in-line math should work fine. {$pos*$alla}
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> General 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