This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

work52598
work52598

Hi,

I'm having issues turning a value from the database into star rating on the front-end. At the moment only static values are being returned from the database using {{item.rate}}. I've linked my code below which works outputting static numbers to the front-end.

<div class="reviews-list">
    {% if __SELF__.reviews %}
    <ul class="rw-list">
        {% for item in __SELF__.reviews %}
        <li>
            <div class="name"><strong>{{item.name}}</strong></div>  
            <div class="rate"><strong>{{item.rate}} Stars</strong></div>

            <div class="text-review">
                {{item.text|raw}}
            </div>
        </li>
        {% endfor %}
    </ul>
    {% endif %}
</div>

Looking at alternative plugins they seem to have used a macro function. However i didn't have much luck getting it to work. Any help would be amazing as i'm new to this side of development.

{% macro rating(value, stars = 5) %}
<span class="stars">
    {% for star in 1..stars %}
    <i class="fas fa-star{% if star > value %}-empty{% endif %}" aria-hidden="true"></i>
    {% endfor %}
    <span>{{ value }} of {{ stars }} stars</span>
</span>
{% endmacro %}
mjauvin
mjauvin

Did you read the docs on how to define/use a macro?

https://octobercms.com/docs/markup/tag-macro

1-2 of 2

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.