How to cycle the smarty area in php
This article describes how to cycle the smarty area in php. Share it with you 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 |
<Html> <Head> <Title> Smarty Test </title> </Head> <Body> <Table border = 1> {Foreach key = key1 item = item1 from = $ array1} <Tr> <Td >{$ key1} </td> <Td >{$ item1} </td> </Tr> {/Foreach} </Table> </Body> </Html> |
| 1 2 3 4 5 6 7 |
<? Php Require 'libs/Smarty. class. php'; // contains the Smarty class library file $ Smarty = new Smarty; // create a new Smarty object $ Array1 = array (1 => "Simon", 2 => "Elaine", 3 => "Susan"); // define an 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 |
<Html> <Head> <Title> Smarty Test </title> </Head> <Body> <Table border = 1> {Section name = section1 loop = $ array1} <Tr> <Td </td> <Td >{$ array1 [section1]} </td> </Tr> {/Section} </Table> </Body> </Html> |
| 1 2 3 4 5 6 7 |
<? Php Require 'libs/Smarty. class. php'; // contains the Smarty class library file $ Smarty = new Smarty; // create a new Smarty object $ Array1 = array (0 => "Simon", 1 => "Elaine", 2 => "Susan"); // define an array $ Smarty-> assign ("array1", $ array1); // assign values to variables in the template $ Smarty-> display('test10.htm'); // display page ?> |