1

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.

Madawar
  • 507
  • 1
  • 9
  • 26

2 Answers2

6
<span class="help-block" tal:condition="exists:password_confirm">
   ${password_confirm}
</span>

should work

Ottavio Campana
  • 4,088
  • 5
  • 31
  • 58
3

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>
Roman Susi
  • 4,135
  • 2
  • 32
  • 47
  • that works but i was looking for something along the lines of tal:omit-tag="not:bold – Madawar Jan 14 '12 at 01:08
  • Not sure how omit-tag could work in this case. It just means, that and will be omitted, but the content will be rendered. – Roman Susi Jan 15 '12 at 15:24