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.

CHAPTER 19 • TEMPLATING WITH SMARTYwww.it-ebooks.infoCommentsComments are used as necessary throughout the remainder of this chapter. Therefore, it seems onlypractical to start by introducing Smarty’s comment syntax. Comments are enclosed within the delimitertags {* and *}; they can consist of a single line or multiple lines. A valid Smarty comment follows:{* Some programming note *}Variable ModifiersAs you learned in Chapter 9, <strong>PHP</strong> offers an extraordinary number of functions capable of manipulatingtext in just about every which way imaginable. You’ll often want to use many of these features fromwithin the presentational layer—for example, to ensure that an article author’s first and last names arecapitalized within the article description. Recognizing this fact, the Smarty developers have incorporatedmany such presentation-specific capabilities into the library. This section introduces many of the moreinteresting features.Before starting the overview, it’s worth first introducing Smarty’s somewhat nontraditional variablemodifier syntax. While the delimiters are used to signal the requested output of a variable, any variablevalue requiring modification prior to output is followed by a vertical bar, followed by the modifiercommand, like so:{$var|modifier}You’ll see this syntax used repeatedly throughout this section as the modifiers are introduced.Capitalizing the First LetterThe capitalize function capitalizes the first letter of all words found in a variable. An example follows:$smarty = new Smarty;$smarty->assign("title", "snow expected in northeast");$smarty->display("article.tpl");The article.tpl template contains the following:{$title|capitalize}This returns the following:Snow Expected In NortheastCounting WordsThe count_words function totals up the number of words found in a variable. An example follows:394

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

Saved successfully!

Ooh no, something went wrong!