Related questions about Smarty!

Source: Internet
Author: User
Tags smarty template
Ask a master about the Smarty problem!!!
The following is an array of shopping carts
$carts =array (
1=>array (name=> "Nokia 5510", price=>800, Qty=>2),
3=>array (name=> "Nokia 6610", price=>1800, Qty=>1),
4=>array (name=> "Nokia 7710", price=>2800, Qty=>1),
7=>array (name=> "Nokia 8810", price=>2500, Qty=>5),
}
Use the Smarty Loop, display the shopping cart in tabular form, the table row background color has the rotation effect, the table has the total statistics


------Solution--------------------
Do the addition in the PHP page and pass in the Smarty template. Smarty doesn't seem to be calculating.

Loop Add-out
$sum
$smarty->assign ("sum", $sum);

Total amount: {$sum}
------Solution--------------------
I checked the manual and can calculate

In math [math] {assign var= "foo" value= "' $foo + $bar '"}

Your template can be written like this
HTML Code
            
  
   
          <title>Untitled Document</title>                
  
  {foreach from= $carts key=k item=item0} {if $k% 2} 
    
      {Else} 
    
      {/if} {foreach from= $item 0 item=item1} 
     {/foreach} 
    {Assign var= "sum" value= "' $sum + $item 0.price '"} {/foreach} 
    
Name Price Number
{$item 1}
Total amount: {$sum}

------Solution--------------------
If you want to do multiplication
{Assign var= "sum" value= "' $sum + $item 0.price* $item 0.qty '"}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.