You are here

flag.html.twig in Flag 8.4

Default theme implementation for flag links.

Available functions:

  • flagcount(flag, flaggable) gets the number of flaggings for the given flag and flaggable.

Available variables:

  • attributes: HTML attributes for the link element.
  • title: The flag link title.
  • action: 'flag' or 'unflag'
  • flag: The flag object.
  • flaggable: The flaggable entity.

File

templates/flag.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for flag links.
  5. *
  6. * Available functions:
  7. * - flagcount(flag, flaggable) gets the number of flaggings for the given flag and flaggable.
  8. *
  9. * Available variables:
  10. * - attributes: HTML attributes for the link element.
  11. * - title: The flag link title.
  12. * - action: 'flag' or 'unflag'
  13. * - flag: The flag object.
  14. * - flaggable: The flaggable entity.
  15. */
  16. #}
  17. {% spaceless %}
  18. {# Attach the flag CSS library.#}
  19. {{ attach_library('flag/flag.link') }}
  20. {# Depending on the flag action, set the appropriate action class. #}
  21. {% if action == 'unflag' %}
  22. {% set action_class = 'action-unflag' %}
  23. {% else %}
  24. {% set action_class = 'action-flag' %}
  25. {% endif %}
  26. {# Set the remaining Flag CSS classes. #}
  27. {%
  28. set classes = [
  29. 'flag',
  30. 'flag-' ~ flag.id()|clean_class,
  31. 'js-flag-' ~ flag.id()|clean_class ~ '-' ~ flaggable.id(),
  32. action_class
  33. ]
  34. %}
  35. {# Set nofollow to prevent search bots from crawling anonymous flag links #}
  36. {% set attributes = attributes.setAttribute('rel', 'nofollow') %}
  37. <div class="{{classes|join(' ')}}"><a{{ attributes }}>{{ title }}</a></div>
  38. {% endspaceless %}