You are here

blazy.html.twig in Blazy 8

Same filename and directory in other branches
  1. 8.2 templates/blazy.html.twig

Default theme implementation to display a formatted blazy image/media field.

The Blazy supports core image, responsive image and media entity. If iframe switcher is enabled, audio/video iframe will be hidden below image overlay, and only visible when toggled. Otherwise iframe only, and image is emptied.

Available variables:

  • image: A collection of image data.
  • attributes: An array of attributes applied to .media container.
  • iframe_attributes: An array of iframe attributes, including iframe SRC.
  • settings: An array containing the given settings.
  • url: An optional URL the image can be linked to, can be any of audio/video, or entity URLs, when using Colorbox/Photobox, or Link to content options.
  • url_attributes: An array of URL attributes, lightbox or content links.

File

templates/blazy.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation to display a formatted blazy image/media field.
  5. *
  6. * The Blazy supports core image, responsive image and media entity.
  7. * If iframe switcher is enabled, audio/video iframe will be hidden below image
  8. * overlay, and only visible when toggled. Otherwise iframe only, and image is
  9. * emptied.
  10. *
  11. * Available variables:
  12. * - image: A collection of image data.
  13. * - attributes: An array of attributes applied to .media container.
  14. * - iframe_attributes: An array of iframe attributes, including iframe SRC.
  15. * - settings: An array containing the given settings.
  16. * - url: An optional URL the image can be linked to, can be any of
  17. * audio/video, or entity URLs, when using Colorbox/Photobox, or Link to
  18. * content options.
  19. * - url_attributes: An array of URL attributes, lightbox or content links.
  20. *
  21. * @see template_preprocess_blazy()
  22. *
  23. * @ingroup themeable
  24. */
  25. #}
  26. {%
  27. set classes = [
  28. 'media',
  29. settings.namespace ? 'media--' ~ settings.namespace,
  30. settings.lazy ? 'media--loading',
  31. settings.media_switch ? 'media--switch media--switch--' ~ settings.media_switch|clean_class,
  32. settings.player ? 'media--player',
  33. settings.ratio ? 'media--ratio media--ratio--' ~ settings.ratio,
  34. settings.responsive_image_style_id ? 'media--responsive',
  35. settings.type ? 'media--' ~ settings.type,
  36. settings.classes ? settings.classes|join(' ')|clean_class,
  37. ]
  38. %}
  39. {%
  40. set iframe_classes = [
  41. 'media__iframe',
  42. settings.ratio ? 'media__element'
  43. ]
  44. %}
  45. {% set player %}
  46. {% if settings.player %}
  47. {% block blazy_player %}
  48. <iframe{{ iframe_attributes.addClass(iframe_classes) }} allowfullscreen></iframe>
  49. {% if settings.media_switch %}
  50. <span class="media__icon media__icon--close"></span>
  51. <span class="media__icon media__icon--play" data-url="{{ settings.autoplay_url }}"></span>
  52. {% endif %}
  53. {% endblock %}
  54. {% endif %}
  55. {% endset %}
  56. {% set media %}
  57. {% block blazy_media %}
  58. <div{{ attributes.addClass(classes) }}>
  59. {{ image }}
  60. {{ player }}
  61. {{ settings.icon }}
  62. </div>
  63. {% endblock %}
  64. {% endset %}
  65. {% set blazy %}
  66. {% block blazy_content %}
  67. {% if media_attributes %}<div{{ media_attributes }}>{% endif %}
  68. {% if url and not settings.player %}
  69. <a href="{{ url }}"{{ url_attributes }}>{{ media }}</a>
  70. {# Allows fieldable captions with A tag, such as social share. #}
  71. {% if captions and captions.lightbox is not empty %}
  72. <div class="litebox-caption visually-hidden">
  73. {{- captions.lightbox -}}
  74. </div>
  75. {% endif %}
  76. {% else %}
  77. {{- media -}}
  78. {% endif %}
  79. {% if media_attributes %}</div>{% endif %}
  80. {% endblock %}
  81. {% if captions and captions.inline is defined %}
  82. {% block blazy_caption %}
  83. <div{{ caption_attributes }}>
  84. {% for caption in captions.inline %}
  85. {% if caption.content %}
  86. <{{ caption.tag }} {{ caption.attributes }}>{{ caption.content }}</{{ caption.tag }}>
  87. {% endif %}
  88. {% endfor %}
  89. </div>
  90. {% endblock %}
  91. {% endif %}
  92. {% endset %}
  93. {% if wrapper_attributes %}
  94. <div{{ wrapper_attributes }}>
  95. {{ blazy }}
  96. </div>
  97. {% else %}
  98. {{ blazy }}
  99. {% endif %}