开发者

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

开发者 https://www.devze.com 2022-12-14 10:36 出处:网络
Coming from PHP world, I used to create select box like this: <select> <?php foreach($arrField as $idx=>$val){?>

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

精彩评论

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