You are here

insert-image.html.twig in Insert 8

Same filename and directory in other branches
  1. 8.2 templates/insert-image.html.twig

Template file for images inserted via the Insert module.

Available variables:

  • class: A set of classes assigned to this image (if any).
  • entity_type: The type of the entity inserted.
  • field_type: The field type the rendered template belongs to, i.e. "file" or "image".
  • height: The height of the image (if known).
  • item: The complete item being inserted.
  • link_to_original: Whether the image shall link to the original image.
  • style_name: The Image style being used.
  • url: The URL to the image being inserted visually; May be a styled image or the full size image.
  • url_original: The URL to the original (full size) image.
  • uuid: The file's UUID.
  • width: The width of the image (if known).

Note that ALT and Title fields should not be filled in here, instead they should use placeholders that will be updated through JavaScript when the image is inserted. Available placeholders:

  • __alt__: The ALT text, intended for use in the <img> tag.
  • __title__: The Title text, intended for use in the <img> tag.
  • __description__: A description of the image, sometimes used as a caption.
  • __filename__: The file name.
  • __[token]_or_filename__: Any of the above tokens if available, otherwise use the file's name. i.e. __title_or_filename__.

File

templates/insert-image.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Template file for images inserted via the Insert module.
  5. *
  6. * Available variables:
  7. * - class: A set of classes assigned to this image (if any).
  8. * - entity_type: The type of the entity inserted.
  9. * - field_type: The field type the rendered template belongs to, i.e. "file" or
  10. * "image".
  11. * - height: The height of the image (if known).
  12. * - item: The complete item being inserted.
  13. * - link_to_original: Whether the image shall link to the original image.
  14. * - style_name: The Image style being used.
  15. * - url: The URL to the image being inserted visually; May be a styled image or
  16. * the full size image.
  17. * - url_original: The URL to the original (full size) image.
  18. * - uuid: The file's UUID.
  19. * - width: The width of the image (if known).
  20. *
  21. * Note that ALT and Title fields should not be filled in here, instead they
  22. * should use placeholders that will be updated through JavaScript when the
  23. * image is inserted. Available placeholders:
  24. * - __alt__: The ALT text, intended for use in the <img> tag.
  25. * - __title__: The Title text, intended for use in the <img> tag.
  26. * - __description__: A description of the image, sometimes used as a caption.
  27. * - __filename__: The file name.
  28. * - __[token]_or_filename__: Any of the above tokens if available, otherwise
  29. * use the file's name. i.e. __title_or_filename__.
  30. */
  31. #}
  32. {% spaceless %}
  33. {% set classes = [] %}
  34. {% if style_name != 'image' %}
  35. {% set classes = classes|merge(['image-' ~ style_name]) %}
  36. {% endif %}
  37. {% if class %}
  38. {% set classes = classes|merge([class]) %}
  39. {% endif %}
  40. {% if link_to_original %}
  41. <a href="{{ url_original }}"{% if class %} class="{{ class }}"{% endif %} data-insert-type="{{ field_type }}">
  42. {% endif %}
  43. <img src="{{ url }}" {% if width and height %}width="{{ width }}" height="{{ height }}" {% endif %}alt="__alt__" title="__title__"{% if classes|length %} class="{{ classes|join(' ') }}"{% endif %} data-insert-type="{{ field_type }}" data-entity-type="{{ entity_type }}" data-entity-uuid="{{ uuid }}" />
  44. {% if link_to_original %}
  45. </a>
  46. {% endif %}
  47. {% endspaceless %}