Edgewall Software

Opened 5 years ago

#407 new enhancement

Improve documentation for py:choose

Reported by: Sebastian Krysmanski <sebastian@…> Owned by: cmlenz
Priority: major Milestone:
Component: Documentation Version: 0.6
Keywords: Cc:


I just tried to use <py:choose> but couldn't get it working. I had this code:

<py:choose test="option.type">
  <span py:when="text">...</span>
  <span py:otherwise="">...</span>

However, the "otherwise" branch was always evaluated even when option.type (which is a string) had "text" as its value.

It took me a while to figure out that "text" in the py:when attribute is not a text but a variable name. The correct code should be (note the ticks in the attribute's value):

<py:choose test="option.type">
  <span py:when="'text'">...</span>
  <span py:otherwise="">...</span>

Although it seems to be logical I think the documentation should include a note about working with strings (as the examples only work with numbers) to avoid this pitfall.

An alternative would be to fall back to evaluate the value of py:when as string rather than an expression. In this case my first example would work. Whether this is actually a good solution may be open to discussions.

Attachments (0)

Change History (0)

Add Comment

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain cmlenz.
as The resolution will be set. Next status will be 'closed'.
to The owner will be changed from cmlenz to the specified user. Next status will be 'new'.
The owner will be changed from cmlenz to anonymous. Next status will be 'assigned'.

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.