开发者

[GAE]How to set `inline` if in template

Coming from PHP world, I used to create select box like this:

<select>
<?php foreach($arrField as $idx=>$val){?>
   <option <?php echo ($fieldVal == $idx ? "selected='selected'" : ''); ?>><?php echo $val; ?></option>
<?php } ?>
</select>

However, I can't do that in python. Here's my snippet:

<select name='type'>
   <option value='normal' {% if开发者_JS百科 id = 'normal' %} selected="selected"{% endif %}>1-Normal</option>
   <option value='image' {% if id = 'image' %} selected="selected"{% endif %}>2-Image</option>
</select>

I got this error:

TemplateSyntaxError: 'if' statement improperly formatted

Is there a way to do this?


You will need to use (if you are using Django):

{% ifequal id "something"%}selected='selected'{% endifequal %}

You will also need to make sure "id" is a variable you pass into templates.Render()

P

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜