Files

38 lines
1.2 KiB
Twig
Raw Permalink Normal View History

{#
# Rating Component (Bootstrap 5)
#
# Reusable star rating display using Bootstrap Icons.
#
# Expected context:
# rating - Numeric rating (0-5)
# review_count - Number of reviews (optional, for display)
#
# Usage:
# {% include 'components/rating.html.twig' with { rating: 4.5, review_count: 12 } %}
#
# @package WcBootstrap
# @since 0.1.0
#}
{% if rating is defined and rating > 0 %}
<div class="wc-star-rating d-inline-flex align-items-center gap-1"
role="img"
aria-label="{{ __('%s out of 5')|format(rating) }}">
{% for i in 1..5 %}
{% if rating >= i %}
<i class="bi bi-star-fill text-warning" aria-hidden="true"></i>
{% elseif rating >= (i - 0.5) %}
<i class="bi bi-star-half text-warning" aria-hidden="true"></i>
{% else %}
<i class="bi bi-star text-warning" aria-hidden="true"></i>
{% endif %}
{% endfor %}
{% if review_count is defined and review_count > 0 %}
<small class="text-body-secondary ms-1">
({{ review_count }})
</small>
{% endif %}
</div>
{% endif %}