0

I'm returning a string body_class to my view. I can't seem to put in a condition without breaking it:

<body tal:condition="body_class" class="${body_class}">
<body tal:condition="not body_class">

Kinda works. It outputs the body class but the rest of the template doesn't work. I'm looking for a solution that puts in the body class if the string exists, otherwise leaves it out.

Dunno what I'm doing wrong.

4

2 回答 2

0

I suppose your talking about a browser view (BorwserView).

Something like that should work if body_class is a method of your BrowserView:

<body tal:condition="view/body_class" class="${view/body_class}">
...
</body>
<body tal:condition="not: view/body_class">
...
</body>
于 2013-09-20T14:58:34.080 回答
0

你不想在tal:condition这里使用;您正在打开或关闭整个元素,包括内容。

您只想设置类属性:

<body tal:attributes="class: body_class">

这适用于空字符串,你只会得到一个空class元素;如果body_classNone,则该属性将被完全省略。

于 2013-09-20T17:02:27.077 回答