How to write loops in Smarty templates

Source: Internet
Author: User
How to write loops in Smarty templates
A half-day tutorial was studied, as if all the loops were for the incoming array

My question is this:
In an incoming array, 8 elements are named from I0 to i7, and now the 8 elements need to be processed
Because this array also contains other elements, it cannot be recycled for arrays
I think it's something like this.
for ($i =0; $i < 8; $i + +)
{
echo $arr ["i$i"];
}
I embed this PHP code in Smarty, and the result seems to be to get the variable $arr, resulting in no output.

Do not know this in the smarty how to achieve, please expert guidance

------Solution--------------------
There's another way of thinking. You can write the array on the PHP page, which is i0-i7, and then loop through the array, where the data is printed.
Like the array you passed is $i.
PHP code
{foreach from= $i item=item}{$arr [$item]} 

--- ---solution--------------------
PHP code
foreach (from= $arr; Key=k item=v) {key: {$k}: value {$v}} 
------solution--------------------
{section name= "fooo" loop= $new _re_j}
{$new _re _id[fooo]}
{/section}

------solution--------------------
Nesting loops in Smarty
------ Solution--------------------
Section foreach Loop;

------Solution--------------------
{foreach from= $i item= Item}
{$arr [$item]}




------Solution--------------------
Why do you do it in Smarty? Is it better to finish working in PHP and then output array display?
------Solution--------------------
Smarty templates are typically looped with foreach

{{foreach from= $test key=key item=i}}

{{/foreach}}
  • 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.