Skip to content

Instantly share code, notes, and snippets.

@taxilian
Created December 14, 2011 06:01
Show Gist options
  • Save taxilian/1475460 to your computer and use it in GitHub Desktop.
Save taxilian/1475460 to your computer and use it in GitHub Desktop.
example of a select statement in an underscore template
<select name="formitem_school">
<% if(schools && schools.length > 0) {
<option value="select_schools">Select School</option>
<% schools.each(function(t) { %>
<option value="<%= t.id %>" <% if(curSchool == t.id){ print('selected'); } %>><%= t.get("name") %></option>
<% });
} else { %>
<option value"schools_none">No Schools</option>
<% }
</select>
@jwerre
Copy link

jwerre commented Apr 16, 2014

Alternatively: <option value="<%= t.id %>" <%= curSchool === t.id ? 'selected' : void 0 } %> >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment