You are here

blazy.html.twig in Blazy 8.2

Same filename and directory in other branches
  1. 8 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.

Important! If you are adding additional contents to any content-related variable here, e.g.: content, overlay, preface, postscript, etc., including icon, be sure to add your own key, normally unique like UUID or module name, to not conflict against, or nullify, other providers, e.g.: Good: postscript.cta, or postscript.widget (This extends postscript) Bad: postscript = cta (This overrides/ nullifies other postscripts with cta)

Available variables:

  • captions: An optional renderable array of inline or lightbox captions.
  • image: A collection of image data.
  • attributes: An array of attributes applied to .media container.
  • iframe: A renderable array of iframe with its attributes and 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.
  • noscript: The fallback image for non-js users.
  • preface: any extra content prefacing the image/ video goes here.
  • overlay: any extra content overlaying the image/ video goes here. Both preface and overlay useful to work with layering, z-index. This opens up possibility for blazy-related modules -- Slick, GridStack, etc. to use blazy.html.twig for their slide or item contents, perhaps at 3+.
  • postscript: Any extra content to put into blazy goes here.
  • content: Various Media entities like Facebook, Instagram, local Video, etc. Basically content is the replacement for (Responsive) image and oEmbed video. This makes it possible to have a mix of Media entities, image and videos on a Blazy Grid, Slick, GridStack, etc. Regular Blazy features are still disabled by default at \Drupal\blazy\BlazyDefault::richSettings() to avoid complication. However you can override them accordingly as needed, such as lightbox for local Video with/o a pre-configured poster image. The #settings are provided under content variables for more work. Originally content is a theme_field() output, trimmed down to bare minimum.

@todo remove media--loading for is-b-loading post sub-module updates.

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. * Important!
  12. * If you are adding additional contents to any content-related variable here,
  13. * e.g.: content, overlay, preface, postscript, etc., including icon, be sure to
  14. * add your own key, normally unique like UUID or module name, to not conflict
  15. * against, or nullify, other providers, e.g.:
  16. * Good: postscript.cta, or postscript.widget (This extends postscript)
  17. * Bad: postscript = cta (This overrides/ nullifies other postscripts with cta)
  18. *
  19. * Available variables:
  20. * - captions: An optional renderable array of inline or lightbox captions.
  21. * - image: A collection of image data.
  22. * - attributes: An array of attributes applied to .media container.
  23. * - iframe: A renderable array of iframe with its attributes and SRC.
  24. * - settings: An array containing the given settings.
  25. * - url: An optional URL the image can be linked to, can be any of
  26. * audio/video, or entity URLs, when using Colorbox/Photobox, or Link to
  27. * content options.
  28. * - url_attributes: An array of URL attributes, lightbox or content links.
  29. * - noscript: The fallback image for non-js users.
  30. * - preface: any extra content prefacing the image/ video goes here.
  31. * - overlay: any extra content overlaying the image/ video goes here. Both
  32. * preface and overlay useful to work with layering, z-index. This opens
  33. * up possibility for blazy-related modules -- Slick, GridStack, etc. to
  34. * use blazy.html.twig for their slide or item contents, perhaps at 3+.
  35. * - postscript: Any extra content to put into blazy goes here.
  36. * - content: Various Media entities like Facebook, Instagram, local Video,
  37. * etc. Basically content is the replacement for (Responsive) image
  38. * and oEmbed video. This makes it possible to have a mix of Media
  39. * entities, image and videos on a Blazy Grid, Slick, GridStack, etc.
  40. * Regular Blazy features are still disabled by default at
  41. * \Drupal\blazy\BlazyDefault::richSettings() to avoid complication.
  42. * However you can override them accordingly as needed, such as lightbox
  43. * for local Video with/o a pre-configured poster image. The #settings
  44. * are provided under content variables for more work. Originally
  45. * content is a theme_field() output, trimmed down to bare minimum.
  46. *
  47. * @see template_preprocess_blazy()
  48. *
  49. * @ingroup themeable
  50. *
  51. * @todo remove media--loading for is-b-loading post sub-module updates.
  52. */
  53. #}
  54. {%
  55. set classes = [
  56. content ? 'media--rendered',
  57. settings.bundle ? 'media--bundle--' ~ settings.bundle|clean_class,
  58. settings.namespace ? 'media--' ~ settings.namespace,
  59. settings.lazy and settings.use_loading ? 'media--loading is-b-loading',
  60. settings.media_switch ? 'media--switch media--switch--' ~ settings.media_switch|clean_class,
  61. settings.player ? 'media--player',
  62. settings.ratio ? 'media--ratio media--ratio--' ~ settings.ratio,
  63. settings.responsive_image_style_id ? 'media--responsive',
  64. settings.type ? 'media--' ~ settings.type,
  65. settings.classes ? settings.classes|join(' ')|clean_class,
  66. ]
  67. %}
  68. {% set player %}
  69. {% block blazy_player %}
  70. {% if settings.player %}
  71. <span class="media__icon media__icon--close"></span>
  72. <span class="media__icon media__icon--play" data-url="{{ settings.embed_url }}"></span>
  73. {% else %}
  74. {{- iframe -}}
  75. {% endif %}
  76. {% endblock %}
  77. {% endset %}
  78. {% set media %}
  79. {% block blazy_media %}
  80. <div{{ attributes.addClass(classes) }}>
  81. {{- preface -}}
  82. {{- noscript -}}
  83. {{- content -}}
  84. {{- image -}}
  85. {{- overlay -}}
  86. {{- player -}}
  87. {# @todo settings.icon is deprecated in 2.0 and is removed from 3.0. Use icon instead. #}
  88. {{- settings.icon -}}
  89. {{- icon -}}
  90. </div>
  91. {% endblock %}
  92. {% endset %}
  93. {% set blazy %}
  94. {% block blazy_content %}
  95. {% if media_attributes %}<div{{ media_attributes }}>{% endif %}
  96. {% if url and not settings.player %}
  97. <a href="{{ url }}"{{ url_attributes }}>{{- media -}}</a>
  98. {# Allows fieldable captions with A tag, such as social share. #}
  99. {% if captions and captions.lightbox is not empty %}
  100. <div class="litebox-caption visually-hidden">
  101. {{- captions.lightbox -}}
  102. </div>
  103. {% endif %}
  104. {% else %}
  105. {{- media -}}
  106. {% endif %}
  107. {% if media_attributes %}</div>{% endif %}
  108. {% endblock %}
  109. {% if captions and captions.inline is defined %}
  110. {% block blazy_caption %}
  111. <div{{ caption_attributes }}>
  112. {% for caption in captions.inline %}
  113. {% if caption.content %}
  114. <{{ caption.tag }} {{ caption.attributes }}>{{- caption.content -}}</{{ caption.tag }}>
  115. {% endif %}
  116. {% endfor %}
  117. </div>
  118. {% endblock %}
  119. {% endif %}
  120. {{- postscript -}}
  121. {% endset %}
  122. {% if wrapper_attributes %}
  123. <div{{ wrapper_attributes }}>
  124. {{- blazy -}}
  125. </div>
  126. {% else %}
  127. {{- blazy }}
  128. {% endif %}