Making smarty tags xhtml compliant: prefilter

From: Date: Mon, 14 Oct 2002 11:26:01 +0000
Subject: Making smarty tags xhtml compliant: prefilter
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-6128@lists.php.net to get a copy of this message
Hello, I have been experimenting with smarty for about a month and I like it, except for the tag format with curly braces. I like the JSP custom tag better (where the tags are xml / xhtml compliant). I have been working on a prefilter which will allow the use of (almost) xhtml compliant Smarty tags. NB. It is not completely xhtml compliant, because in smart tags, attribute values that are smarty variables may not have double quotes around them (e.g. <test att=$attvalue />. I would prefer to be able to do <test att="$attvalue" />. Each tag is provided with a prefix which must be defined at the beginning of the template. There are two types of prefixes, (1) prefixes that are not added to the smarty tag name (e.g <smarty:literal> becomes {literal})(2) prefixes that ARE added to the smarty tag name (e.g. <html:select_date /> becomes {html_select_date }). For prefix type (1) use the code "tagPrefix", for prefix type (2) use tagPrefixAdd (see below for an example). The latter prefix type allows for a better classification of different plugins, so that a set of plugins can be grouped together by a simlilar prefix. This encourages cleaner template code (IMO). For an example see the use of a table tag family I am working on below. There are three plugins: - table_table - table_row - table_column which are grouped together using the "table" prefix. For this reason I have renamed some of the form plugins from html_* to form_* so that I can use all of the form plugins in a form context. For an an template example see below: ***** start sample code ******* <!@tagPrefix="smarty"> <!@tagPrefixAdd="table"> <!@tagPrefixAdd="form"> <!@tagPrefixAdd="html"> <html> <head> <title>{$title}</title> <smarty:literal> <!-- will be converted to {literal} --> <style> .col1 {background: blue;} .col2 {background: green;} .col3 {background: yellow; } </style> </smarty:literal> <!-- will be converted to {/literal} --> </head> <body> <form action="none"> <html:select_date display_days="yes" /> <!-- will be converted to {html_select_date } --> <select name="gender" multiple="multiple" size="2"> <form:options options=$gender_options selected=$testgender /> </select> <form:radio name="radio" options=$gender_options selected=$testgender /> </form> </form> <table:table border=1> <table:row class="test" valign="top" height="50" max_rows=$data.max_rows total_rows=$data.total_rows array=$personList > <table:column type="numbering" class="col1" placecontent="before" >No. </table:column> <table:column name="firstname" class="col2" header="First Name" sort="true"> </table:column> <table:column name="lastname" class="col3" header="Last Name" sort="true"> </table:column> </table:row> </table:table> </body> </html> ***** end sample code ******* There is one limition in the current plugin: attribute values may not have the value "<" in them. When the attribute value is a smarty variable, this limitation does not apply. e.g. <test att="<b>bold text</b>" /> is not allowed. however <test att=$bold_text /> , where $bold_text has the value <b>bold text</b> *IS* allowed. Greetings, Martijn -------------------------------------------------------------------- mail2web - Check your email from the web at http://mail2web.com/ .

« previous php.smarty.general (#6128) next »