11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 19 • TEMPLATING WITH SMARTY"author" => "Magnus Lie Hetland","published" => "2005");$smarty->assign("titles", $titles);$smarty->display("section2.tpl");The section2.tpl template contains the following:{section name=book loop=$titles}Title: {$titles[book].title}Author: {$titles[book].author}Published: {$titles[book].published}{/section}This returns the following:Title: Pro <strong>PHP</strong>Author: Kevin McArthurPublished: 2008Title: Beginning PythonAuthor: Magnus Lie HetlandPublished: 2005The sectionelse FunctionThe sectionelse function is used in conjunction with section and operates much like the defaultfunction does for strings, producing some alternative output if the array is empty. An example of atemplate using sectionelse follows:{section name=book loop=$titles}{$titles[book]}{sectionelse}No entries matching your query were found.{/section}Note that sectionelse does not use a closing bracket; rather, it is embedded within section, muchlike an elseif is embedded within an if function.StatementsSmarty offers several statements to perform special tasks. This section introduces several of thesestatements.The include StatementThe include statement operates much like the statement of the same name found in the <strong>PHP</strong>distribution, except that it is to be used solely for including other templates into the current template.401

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!