Chapter 12 Answers

Question 12-1

There are several benefits to using a templating system such as Smarty. They include but are not limited to:

  • Separating the program code from the presentation layer.

  • Preventing template editors from modifying program code.

  • Removing the need for programmers to design page layout.

  • Allowing the redesign of a web page without modifying any program code.

  • Enabling multiple “skin” designs with little recourse to modifying program code.

Question 12-2

To pass a variable to a Smarty template, a PHP program uses the $smarty->assign function.

Question 12-3

Smarty templates access variables passed to them by prefacing them with a dollar sign $ and enclosing them with curly braces {}.

Question 12-4

To iterate through an array in a Smarty template, you use the opening {section} and closing {/section} tags.

Question 12-5

If Smarty has been installed, you can enable it in a PHP program by including the Smarty.class.php file from its correct location (normally in a folder called Smarty, just under the document root).

Get Learning PHP, MySQL, and JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.