Reputation: 507
I have created a .pt template as that contains the following snippet
<span class="help-block">
${password_confirm}
</span>
My Problem is that the password_confirm field will not always be rendered by pyramid framework so it displays the error below
chameleon.utils.NameError
NameError: password_confirm
I understand i am suppose to use a tal:condition but everything i am trying is failing. Can someone help me on how i am suppose to go about variables that will not always be rendered in the template.
Upvotes: 1
Views: 1154
Reputation: 4188
<span class="help-block" tal:condition="exists:password_confirm">
${password_confirm}
</span>
should work
Upvotes: 6
Reputation: 4199
Maybe you can add tal:on-error="nothing"
in the span tag. Then, if error occurs, the whole span will not be rendered.
<span class="help-block" tal:on-error="nothing">
${password_confirm}
</span>
You can use something else instead of nothing.
UPDATE: this approach is not generally advisable, but can be useful as simplest in some cases.
UPDATE2: another variant (not checked with Chameleon)
<span class="help-block" tal:condition="password_confirm|nothing">
${password_confirm}
</span>
Upvotes: 3