CHAPTER 11 – Flexy HTML Attribute Handling
One of the interesting things about Flexy is how it handles HTML/XML elements and attributes in the template. To give you an example, here is the last example again with the template changed to use a Flexy HTML/XML attribute for controlling a block: <html> <head> <title>{title}</title> </head> <body> <h1>{title}</h1> <ul> <li flexy:foreach="list_entries,text">{text}</li> </ul> (End of list) </body> </html> The {foreach:} construct is gone; it is replaced by an attribute to the ele- ment that is being repeated: <li>. This looks a bit like XML namespaces, but it is not; the Flexy compiler removes the flexy:foreach attribute during compila- tion, and generates the same PHP code as the {foreach:} variant. The com- piled version of this template looks like this:
html> <head> <title><?php echo htmlspecialchars($t->title);?></title> </head> <body> <h1><?php echo htmlspecialchars($t->title);?></h1> <ul> <?php if (is_array($t->list_entries) || is_object($t- >list_entries)) foreach($t->list_entries as $entry_text) {?><li><?php echo htmlspecialchars($entry_text);?></li><?php }?> </ul> (End of list) </body> </html> The XML/HTML attributes supported by Flexy are outlined in Table 11.3. Table 11.3 Flexy HTML/XML Attributes Attribute Description flexy:if="variable" This is a simplified {if:}. The condition applies to the flexy:if="method()" XML/HTML element and its subelements, and there is no flexy:if="!variable" {else:}. If the test is false, the current element and all its flexy:if="!method()" child elements are ignored. flexy:start="here" The flexy:start attribute can be used to ignore every- thing outside the current element. This is useful if you have sub-templates but still want to be able to view or edit them as complete HTML files. flexy:startchil- Similar to flexy:start, but ignores everything to and dren="here" including the current element. flexy:ignore="yes" Ignores the current element and all child elements. It's useful to put mock-up data in templates that are edited with some visual web-design tool. flexy:ignore- Ignores all child elements, but not the current element. only="yes"