Using Dwoo with loops - Blog example
Let's assume you are looping over multiple articles of a blog that you want to display, here is what you can do to do it as lightly as possible :
You first have to create an "article.tpl" template file, the name doesn't matter really it's up to you, here is what goes in :
{$title}
{$content}
You will then use this template to render all the articles.
include 'path/to/dwooAutoload.php';
$dwoo = new Dwoo();
// Load the "article" template
$tpl = new Dwoo_Template_File('path/to/article.tpl');
// Retrieve your data using whatever means you use
$articles = getMyArticles();
// Loop over them
foreach($articles as $article) {
// Output each article using their data (assuming it is an
// associative array containing "title", "content", "author"
// and "date" keys)
$dwoo->output($tpl, $article);
}
No comments:
Post a Comment