Reputation: 1389
I'm trying to add a class "semi" to a star rating system I'm making with Twig. I can't create custom functions so it need to be done "frontend".
What I tried is this:
{% for i in range(0, 5, 0.5) | limit(5) %} {# limit to 5 stars #}
{% set starClass = (productScore >= i ? "on" : "off") %}
<span class="star fa fa-star {{ starClass }}"></span>
{% endfor %}
When productScore
equals 3 I get a result like:
<span class="star fa fa-star on"></span>
<span class="star fa fa-star on"></span>
<span class="star fa fa-star on"></span>
<span class="star fa fa-star off"></span>
<span class="star fa fa-star off"></span>
But how can I create a function that also add a classname semi
when productScore
equals 3.5??
<span class="star fa fa-star on"></span>
<span class="star fa fa-star on"></span>
<span class="star fa fa-star on"></span>
<span class="star fa fa-star semi"></span>
<span class="star fa fa-star off"></span>
Somebody have any idea?
Upvotes: 0
Views: 342