Simple snippet/partial for a twig star rating with fontawesome

<div>
    {% if bewertung %}
        {% for i in range(1,5) %}
            {% if  bewertung >=  max(0, i-0.25) %}
                <span class="fa fa-star"></span>
            {% elseif (bewertung > (i-0.75)) %}
                <span class="fa fa-star-half-o"></span>
            {% else %}
                <span class="fa fa-star-o"></span>
            {% endif %}
        {% endfor %}
        <span>{{ bewertung }}/5</span>
    {% else %}
        <span class="fa fa-star-o"></span>
        <span class="fa fa-star-o"></span>
        <span class="fa fa-star-o"></span>
        <span class="fa fa-star-o"></span>
        <span class="fa fa-star-o"></span>
        <span>(k.a.)</span>
    {% endif %}
</div>

 

Categories: HTML