Smarty for Beginners - The Basics
(Page 3 of 5 )
The basic operation of a template engine is to assign variables or arrays and integrate them with your html page.
Let's try something simple first. Open your index.php page and add this line before the $smarty->display function.
$smarty->assign ("name", "Hermawan Haryanto"); |
Open your index.html page and add this line:
The result would be:
My name is Hermawan Haryanto |
Now, let's try assigning arrays to your template. Add these lines in index.php remembering all added lines would be before the $smarty->display function.
$friends = array("Mike", "Simpson", "Bill", "Torvald", "Paul", "John Doe"); $smarty->assign ("friends", $friends); |
Open your index.html page and add these lines:
Friends List: {section name=i loop=$friends} {$friends[i]}<br> {/section} |
You'll see the array is pulled and populated on the html page.
Next: What about accessing a database? >>
More Miscellaneous Articles
More By Hermawan Haryanto
|
| · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | · | | | | |
|