How to loop smarty areas in php
This article describes the method of looping smarty areas in php. Share it with everyone for your reference. The specific implementation method is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Smarty Test
{foreach key=key1 item=item1 from=$array1}
{$key1} |
{$item1} |
{/foreach}
|
1
2
3
4
1
2
3
4
5
6
7
|
require 'libs/Smarty.class.php'; //包含Smarty类库文件
$smarty = new Smarty; //创建一个新的Smarty对象
$array1 = array(1 => "Simon", 2 => "Elaine", 3 => "Susan"); //定义数组
$smarty->assign("array1",$array1); //对模版中的变量赋值
$smarty->display('test3.htm'); //显示页面
?>
|
5
6
7
8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Smarty Test
{section name=section1 loop=$array1}
| {$array1[section1]} |
{/section}
|
9
10
11
12
13
1
2
3
4
5
6
7
|
require 'libs/Smarty.class.php'; //包含Smarty类库文件
$smarty = new Smarty; //创建一个新的Smarty对象
$array1 = array(0 => "Simon", 1 => "Elaine", 2 => "Susan"); //定义数组
$smarty->assign("array1",$array1); //对模版中的变量赋值
$smarty->display('test10.htm'); //显示页面
?>
|
14
15
|
Smarty Test
{foreach key=key1 item=item1 from=$array1}
{$key1} |
{$item1} |
{/foreach}
|
1
2
3
4
5
6
7
|
<🎜>require 'libs/Smarty.class.php'; //Contains Smarty class library files<🎜>
<🎜>$smarty = new Smarty; //Create a new Smarty object<🎜>
<🎜>$array1 = array(1 => "Simon", 2 => "Elaine", 3 => "Susan"); //Define array
$smarty->assign("array1",$array1); //Assign values to variables in the template
$smarty->display('test3.htm'); //Display page
?>
|
Another method:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
Smarty Test
{section name=section1 loop=$array1}
| {$array1[section1]} |
{/section}
|
1
2
3
4
5
6
7
|
<🎜>require 'libs/Smarty.class.php'; //Contains Smarty class library files<🎜>
<🎜>$smarty = new Smarty; //Create a new Smarty object<🎜>
<🎜>$array1 = array(0 => "Simon", 1 => "Elaine", 2 => "Susan"); //Define array<🎜>
<🎜>$smarty->assign("array1",$array1); //Assign values to variables in the template
$smarty->display('test10.htm'); //Display page
?>
|
http://www.bkjia.com/PHPjc/1015340.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1015340.htmlTechArticleThe smart area loop method in php. This article describes the smart area loop method in php. Share it with everyone for your reference. The specific implementation method is as follows: 1 2 3 4 5 6 7 8 9 10 11 12 1...