[PHPTAL] tal:content with php:

Jonathan Vanasco phptal at 2xlp.com
Thu May 3 18:48:49 CEST 2007


On May 3, 2007, at 12:47 AM, James McLean wrote:

> <span tal:omit-tag="" tal:condition="exists: productdetail/ 
> productdiscounted">

the tal:omit-tag is worthless.  it needs to be "string:1" or  
something that will evaluate to true.  that will never pass.

>    <option value="0"
> 		selected="selected"
> 		tal:attributes="value productdetail/productdiscounted"
> 		tal:content="php: (productdetail.productdiscounted eq '1') ?  
> 'Yes' : 'No' "
>    ></option>
>    <option>----</option>
> </span>

This section is weird.  Why put the selected item in the dropdown 2x?

you might be better off doing something like this:

> <option value="0" tal:attributes="selected productdetail/ 
> productdiscounted/0">No</option>
> <option value="1" tal:attributes="selected productdetail/ 
> productdiscounted/1">Yes</option>

then just pass to TAL a datastructure like this
	productdetail=>
		productdiscounted=>
			$selected_item=> 'selected'
	
you could also loop it

> <option tal:repeat="product productdetail" tal:attributes="value  
> product/value ; selected product/selected" tal:content="product/ 
> as_text">No</option>

	productdetail=>
		0=>
			value => 99
			selected => undef
			as_text=> No
		1=>
			value => 98
			selected => selected
			as_text=> Yes

both of those ways will work in more tal implementations that using a  
php block.



More information about the PHPTAL mailing list