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 SMARTYThe name parameter is special in the sense that it designates a namespace of sorts that is specific tothe contents intended to be inserted by the insertion statement. When the insert tag is encountered,Smarty seeks to invoke a user-defined <strong>PHP</strong> function named insert_name(), and will pass any variablesincluded with the insert tag via the var parameters to that function. Whatever output is returned fromthis function will then be output in the place of the insert tag.Consider a template that looks like this:Once encountered, Smarty will reference any available user-defined <strong>PHP</strong> function namedinsert_banner() and pass it two parameters, namely height and width.The literal StatementThe literal statement signals to Smarty that any data embedded within its tags should be output as is,without interpretation. It’s most commonly used to embed JavaScript and CSS (cascading style sheets)into the template without worrying about clashing with Smarty’s assigned delimiter (curly brackets bydefault). Consider the following example in which some CSS markup is embedded into the template:Welcome, {$user}{literal}p {margin: 5px;}{/literal}...Neglecting to enclose the CSS information within the literal brackets would result in a Smartygeneratedparsing error because it would attempt to make sense of the curly brackets found within theCSS markup (assuming that the default curly-bracket delimiter hasn’t been modified).The php StatementYou can use the php statement to embed <strong>PHP</strong> code into the template. Any code found within the {php}{/php}tags will be handled by the <strong>PHP</strong> engine. An example of a template using this function follows:Welcome to my Web site.{php}echo date("F j, Y"){/php}This is the result:Welcome to my Web site.July 17, 2010403

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

Saved successfully!

Ooh no, something went wrong!