[PHPTAL] Conditional Attribute Output

Jonathan Vanasco phptal at 2xlp.com
Sat Jul 14 19:03:55 CEST 2007


On Jul 13, 2007, at 2:38 AM, lbedubourg wrote:

> Yes, but since TALES does not support anything but boolean  
> conditions you will have to use the php: modifier.

I think you'd be better off making it strict-TAL compliant code

you can use a tal:define that never renders to set a variable within  
tal, then toss those variables into attributes later on.

its an extra 2 steps, but your templates will work on phptal, perl  
implemtnations and zpt.

here's a sample:

			<table cellpadding="4" cellspacing="0" border="0"  
class="table_shouts">
				<tr>
					<td class="headerTitleOdd" width="200">Date</td>
					<td class="headerTitleEven">Shout</td>
				</tr>
				<tag tal:omit-tag="" tal:repeat="broadcast Shouts">
					<tag tal:omit-tag="" tal:condition="repeat/even"><tag  
tal:define="rowClass string:rowEven" tal:omit-tag=""/></tag>
					<tag tal:omit-tag="" tal:condition="repeat/odd"><tag  
tal:define="rowClass string:rowOdd" tal:omit-tag=""/></tag>
					<tr tal:attributes="class rowClass">
						<td class="colOdd" tal:content="broadcast/ 
F_timestamp_created">F_timestamp_created</td>
						<td class="colEven" tal:content="broadcast/ 
F_shout_text_unescaped">F_shout_text_unescaped</td>
					</tr>
				</tag>
			</table>




More information about the PHPTAL mailing list