For the complete documentation index, see llms.txt. This page is also available as Markdown.

Displaying reviews

Everything on this page uses product.getReviews(), which returns submitted reviews only, so it is safe to loop over on a public page.

The minimum

{% for review in product.getReviews() %}
  <article>
    <p>{{ review.rating }} out of 5</p>
    <p>{{ review.renderComment() ?? 'No comment' }}</p>
    <time datetime="{{ review.dateCreated|atom }}">{{ review.dateCreated|date('medium') }}</time>
  </article>
{% else %}
  <p>No reviews yet.</p>
{% endfor %}

The average and a count

{% set reviews = product.getReviews() %}

{% if reviews|length %}
  <p>{{ product.averageRating }} out of 5, from {{ reviews|length }} reviews</p>
{% endif %}

Stars without images

The aria-label matters. Without it a screen reader announces a row of star characters, which tells the listener nothing.

A ratings breakdown

getRatingCountInList() omits ratings that nobody gave, so look each one up rather than looping over the result.

Showing which variant was bought

Showing who wrote it

A customer can be deleted while their review remains, so guard the reviewer.

The same applies to review.product when you are looping over reviews from craft.productReview.getReviews() rather than from one product.

Filtering and sorting

Sorting products by rating