Skip to content

Instantly share code, notes, and snippets.

@armetiz
Created June 9, 2016 09:16
Show Gist options
  • Save armetiz/ca707522ba5d491c184fdbeb92f67c26 to your computer and use it in GitHub Desktop.
Save armetiz/ca707522ba5d491c184fdbeb92f67c26 to your computer and use it in GitHub Desktop.
{% macro stars(rating, max) %}
<div class="stars">
{% for i in range(1, max) %}
{% set toggled = (i <= rating|round) %}
{% set half = (rating|round == i and rating|round(0, 'floor') != rating) %}
{% if half %}
{% set className = "fa-star-half-o" %}
{% elseif toggled %}
{% set className = "fa-star" %}
{% else %}
{% set className = "fa-star-o" %}
{% endif %}
<i class="fa fa-2x {{ className }}" aria-hidden="true"></i>
{% endfor %}
</div>
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment