Skip to content

Instantly share code, notes, and snippets.

@ThisIsMissEm
Created October 30, 2014 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThisIsMissEm/a2e7db1d033cece7cac7 to your computer and use it in GitHub Desktop.
Save ThisIsMissEm/a2e7db1d033cece7cac7 to your computer and use it in GitHub Desktop.
{% macro select_for(model, name, options, selected) %}
<select class="form-control" id="{{ name }}" name="{{ model }}[{{ name }}]">
{% for option in options %}
{{ option_tag(option.value, option.title, option.value == selected) }}
{% endfor %}
</select>
{% endmacro %}
{% macro option_tag(value, title, selected=false) %}
{% if not title %}
{% set title = value|title %}
{% endif %}
{% if selected %}
<option value="{{value}}" selected>{{ title }}</option>
{% else %}
<option value="{{value}}">{{ title }}</option>
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment