2012-07-11 46 views

回答

2

tal:attributes列出的属性被设置为无,省略该属性:

<span tal:attributes="title python:len(item['title']) < 10 and item['title'] or None"> 
    Only a title if shorter than 10 characters. 
</span> 

这同样适用于路径表达式不存在的对象:

<span tal:attributes="title item/title" /> 

现在title属性只有在项目上的标题密钥或属性时才会设置。请注意,如果item/title解析为None,那么该属性也会被省略。

TALES 1.4 specification, attributes section

如果与属性分配相关联的表达式的计算结果不了了之,那么该属性是从语句元素中删除。

其中python None被解释为“无”。

相关问题