Question

I'm using Chameleon in a Python website I'm developing. Here's a snippet of code:

<option tal:repeat="option options"
        value="${option.isoformat()}"
        selected="${if request.get_param('%s%d%s' %(day, row, type))==option.isoformat(): 'selected'}">
    ${int(option.strftime('%I'))}${option.strftime(':%M%p')}
</option>

But for some reason I always get a syntax error:

ExpressionError: invalid syntax

- String:   "if request.get_param('%s%d%s' %(day, row, type))==option.isoformat(): 'selected'"
- Filename: /Users/theron/Sites/python/restaurateur/views/settings/hours.pt

I don't see what I'm doing wrong. Any help?

Was it helpful?

Solution

Alright, I think I figured it out: It was invalid because there was no else statement, so there was no output when the if statement evaluated to false. I fixed it with the following:

<option tal:repeat="option options"
        value="${option.isoformat()}"
        tal:attributes="selected 'selected' if request.get_param('%s%d%s' %(day, row,
        type))==option.isoformat() else None">
    ${int(option.strftime('%I'))}${option.strftime(':%M%p')}
</option>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top