Edgewall Software

Ticket #407 (new enhancement)

Opened 4 years ago

Improve documentation for py:choose

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

Description

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>
</py:choose>

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>
</py:choose>

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

Add/Change #407 (Improve documentation for py:choose)

Author


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


Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change from cmlenz. Next status will be 'new'
The owner will change from cmlenz to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.