ariefbayu
ariefbayu

Reputation: 21979

[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 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?

Upvotes: 1

Views: 2152

Answers (1)

Kinlan
Kinlan

Reputation: 16607

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

Upvotes: 2

Related Questions