mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-04 10:24:26 +02:00
update QUICKSTART guide with index key example
This commit is contained in:
27
QUICKSTART
27
QUICKSTART
@@ -259,6 +259,33 @@ the section that display the loop iteration and the total number of times the
|
|||||||
section is looped. Also note the {sectionelse}. This would have been displayed
|
section is looped. Also note the {sectionelse}. This would have been displayed
|
||||||
had the loop array $FirstName been empty.
|
had the loop array $FirstName been empty.
|
||||||
|
|
||||||
|
You can access keys of arrays with this syntax:
|
||||||
|
|
||||||
|
--------- index.php --------
|
||||||
|
<?php
|
||||||
|
require("Smarty.class.php");
|
||||||
|
$smarty = new Smarty;
|
||||||
|
$smarty->assign(array("ContactInfo" => array(
|
||||||
|
array("FirstName" => "Ned","LastName" => "Flanders"),
|
||||||
|
array("FirstName" => "Monty","LastName" => "Burns")
|
||||||
|
)
|
||||||
|
));
|
||||||
|
$smarty->display("index.tpl");
|
||||||
|
?>
|
||||||
|
|
||||||
|
--------- templates/index.tpl --------
|
||||||
|
{include file="header.tpl" title="Home Page"}
|
||||||
|
{section name=people loop=$ContactInfo}
|
||||||
|
{$ContactInfo[people].FirstName}
|
||||||
|
{$ContactInfo[people].LastName}<br>
|
||||||
|
{sectionelse}
|
||||||
|
There are no values to loop through.
|
||||||
|
{/section}
|
||||||
|
<p>
|
||||||
|
There were {%people.loop%} names in this list.
|
||||||
|
{include file="footer.tpl"}
|
||||||
|
|
||||||
|
|
||||||
You can also do complex nested sections, like so:
|
You can also do complex nested sections, like so:
|
||||||
|
|
||||||
--------- index.php --------
|
--------- index.php --------
|
||||||
|
@@ -1,7 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
|
|
||||||
require("Smarty.class.php");
|
require("Smarty.class.php");
|
||||||
|
|
||||||
$smarty = new Smarty;
|
$smarty = new Smarty;
|
||||||
|
@@ -812,7 +812,7 @@ $smarty->clear_all_cache();
|
|||||||
<title>clear_compiled_tpl</title>
|
<title>clear_compiled_tpl</title>
|
||||||
<funcsynopsis>
|
<funcsynopsis>
|
||||||
<funcprototype>
|
<funcprototype>
|
||||||
<funcdef>void <function>clear_all_cache</function></funcdef>
|
<funcdef>void <function>clear_compiled_tpl</function></funcdef>
|
||||||
<paramdef>string <parameter>tpl_file</parameter></paramdef>
|
<paramdef>string <parameter>tpl_file</parameter></paramdef>
|
||||||
</funcprototype>
|
</funcprototype>
|
||||||
</funcsynopsis>
|
</funcsynopsis>
|
||||||
|
Reference in New Issue
Block a user