You are here

fivestar-summary.html.twig in Fivestar 8

Default theme implementation for the Fivestar summary output.

Note that passing in explicit data types is extremely important for the next variables in this template:

  • average_rating
  • user_rating
  • votes

A NULL value will exclude the value entirely from display, while a 0 value indicates that the text should be shown but it has no value yet.

Available variables

  • average_rating: The desired average rating to display out of 100 (i.e. 80 is 4 out of 5 stars), or NULL for not to show average rating. Defaults to NULL.
  • votes: The total number of votes.
  • stars: The number of stars being displayed.
  • microdata: An additional data to show rating in the search engines results.
  • user_rating: The rating set by the user on the enclosing entity as an integer 1..100, or NULL for not to show user rating. Defaults to NULL.
  • average_rating_microdata: An additional data to show average rating in the search engines results.
  • rating_count_microdata: An additional data to show the number of votes in the search engines results.
  • average_stars: rounded rating to display (example: 4.0)
  • output_type: a word indicating the desired output style. One of:
    • "user" when display user rating.
    • "user-count" when display votes number and user rating.
    • "average" when display average rating.
    • "average-count" when display votes number and average rating.
    • "combo" when display user and average rating.
    • "count" when display the number of the votes.

File

templates/fivestar-summary.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for the Fivestar summary output.
  5. *
  6. * Note that passing in explicit data types is extremely important for the next
  7. * variables in this template:
  8. * - average_rating
  9. * - user_rating
  10. * - votes
  11. * A NULL value will exclude the value entirely from display, while a 0 value
  12. * indicates that the text should be shown but it has no value yet.
  13. *
  14. * Available variables
  15. * - average_rating: The desired average rating to display out of 100 (i.e. 80
  16. * is 4 out of 5 stars), or NULL for not to show average rating.
  17. * Defaults to NULL.
  18. * - votes: The total number of votes.
  19. * - stars: The number of stars being displayed.
  20. * - microdata: An additional data to show rating in the search engines
  21. * results.
  22. * - user_rating: The rating set by the user on the enclosing entity as an
  23. * integer 1..100, or NULL for not to show user rating. Defaults to NULL.
  24. * - average_rating_microdata: An additional data to show average rating
  25. * in the search engines results.
  26. * - rating_count_microdata: An additional data to show the number of votes in
  27. * the search engines results.
  28. * - average_stars: rounded rating to display (example: 4.0)
  29. * - output_type: a word indicating the desired output style. One of:
  30. * - "user" when display user rating.
  31. * - "user-count" when display votes number and user rating.
  32. * - "average" when display average rating.
  33. * - "average-count" when display votes number and average rating.
  34. * - "combo" when display user and average rating.
  35. * - "count" when display the number of the votes.
  36. *
  37. * @see template_preprocess_fivestar_summary()
  38. *
  39. * @ingroup themeable
  40. */
  41. #}
  42. {% set classes = ['fivestar-summary', 'fivestar-summary-' ~ output_type] %}
  43. <div{{ attributes.addClass(classes) }}>
  44. {% if user_rating %}
  45. <span class="user-rating">
  46. {{ 'Your rating:'|t }} <span>{{ user_stars }}</span>
  47. </span>
  48. {% endif %}
  49. {% if average_rating %}
  50. <span class="average-rating">
  51. {{ 'Average:'|t }} <span{{ average_rating_microdata }}>{{ average_stars }}</span>
  52. </span>
  53. {% endif %}
  54. {% if votes is not empty %}
  55. {% if votes == 0 %}
  56. <span class="empty">{{ 'No votes yet'|t }}</span>
  57. {% else %}
  58. <span class="total-votes">
  59. {% set votes_suffix = votes > 1 ? 'votes'|t : 'vote'|t %}
  60. {% if user_rating or average_rating %}
  61. (<span{{ rating_count_microdata }}>{{ votes }}</span> {{ votes_suffix }})
  62. {% else %}
  63. <span{{ rating_count_microdata }}>{{ votes }}</span> {{ votes_suffix }}
  64. {% endif %}
  65. </span>
  66. {% endif %}
  67. {% endif %}
  68. </div>