You are here

slick.html.twig in Slick Carousel 8

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

Default theme implementation for the Slick carousel template.

This template holds 3 displays: main, thumbnail and overlay slicks in one. Arrows are enforced, but toggled by JS accordingly. This allows responsive object to enable and disable it as needed without losing context.

Available variables:

  • items: The array of items containing main image/video/audio, optional image/video/audio overlay and captions, and optional thumbnail texts/images.
  • settings: A cherry-picked settings that mostly defines the slide HTML or layout, and none of JS settings/options which are defined at data-slick.
  • attributes: The array of attributes to hold the main container classes, id.
  • content_attributes: The array of attributes to hold optional RTL, id and data-slick containing JSON object aka JS settings the Slick expects to override default options. We don't store these JS settings in the normal <head>, but inline within data-slick attribute instead.

Debug: Use Kint: {{ kint(variable) }} Dump all available variables and their contents: {{ dump() }} Dump only the available variable keys: {{ dump(_context|keys) }}

File

templates/slick.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for the Slick carousel template.
  5. *
  6. * This template holds 3 displays: main, thumbnail and overlay slicks in one.
  7. * Arrows are enforced, but toggled by JS accordingly. This allows responsive
  8. * object to enable and disable it as needed without losing context.
  9. *
  10. * Available variables:
  11. * - items: The array of items containing main image/video/audio, optional
  12. * image/video/audio overlay and captions, and optional thumbnail
  13. * texts/images.
  14. * - settings: A cherry-picked settings that mostly defines the slide HTML or
  15. * layout, and none of JS settings/options which are defined at data-slick.
  16. * - attributes: The array of attributes to hold the main container classes, id.
  17. * - content_attributes: The array of attributes to hold optional RTL, id and
  18. * data-slick containing JSON object aka JS settings the Slick expects to
  19. * override default options. We don't store these JS settings in the normal
  20. * <head>, but inline within data-slick attribute instead.
  21. *
  22. * Debug:
  23. * @see https://www.drupal.org/node/1906780
  24. * @see https://www.drupal.org/node/1903374
  25. * Use Kint: {{ kint(variable) }}
  26. * Dump all available variables and their contents: {{ dump() }}
  27. * Dump only the available variable keys: {{ dump(_context|keys) }}
  28. */
  29. #}
  30. {%
  31. set classes = [
  32. 'slick',
  33. settings.unslick ? 'unslick',
  34. display == 'main' and settings.blazy ? 'blazy',
  35. settings.vertical ? 'slick--vertical',
  36. settings.attributes.class ? settings.attributes.class|join(' '),
  37. settings.skin ? 'slick--skin--' ~ settings.skin|clean_class,
  38. 'boxed' in settings.skin ? 'slick--skin--boxed',
  39. 'split' in settings.skin ? 'slick--skin--split',
  40. settings.optionset ? 'slick--optionset--' ~ settings.optionset|clean_class,
  41. arrow_down_attributes is defined ? 'slick--has-arrow-down',
  42. settings.asNavFor ? 'slick--' ~ display|clean_class,
  43. settings.slidesToShow > 1 ? 'slick--multiple-view',
  44. settings.count <= settings.slidesToShow ? 'slick--less',
  45. display == 'main' and settings.media_switch ? 'slick--' ~ settings.media_switch|clean_class,
  46. display == 'thumbnail' and settings.thumbnail_caption ? 'slick--has-caption'
  47. ]
  48. %}
  49. {%
  50. set arrow_classes = [
  51. 'slick__arrow',
  52. settings.vertical ? 'slick__arrow--v',
  53. settings.skin_arrows ? 'slick__arrow--' ~ settings.skin_arrows|clean_class
  54. ]
  55. %}
  56. <div{{ attributes.addClass(classes) }}>
  57. {% if not settings.unslick %}
  58. <div{{ content_attributes.addClass('slick__slider') }}>
  59. {% endif %}
  60. {% block slick_content %}
  61. {% for item in items %}
  62. {{ item }}
  63. {% endfor %}
  64. {% endblock %}
  65. {% if not settings.unslick %}
  66. </div>
  67. {% block slick_arrow %}
  68. <nav{{ arrow_attributes.addClass(arrow_classes) }}>
  69. <button type="button" data-role="none" class="slick-prev" aria-label="{{ settings.prevArrow|t }}" tabindex="0">{{ settings.prevArrow|t }}</button>
  70. {% if arrow_down_attributes is defined %}
  71. <button{{ arrow_down_attributes.addClass('slick-down')
  72. .setAttribute('type', 'button')
  73. .setAttribute('data-target', settings.downArrowTarget)
  74. .setAttribute('data-offset', settings.downArrowOffset) }}></button>
  75. {% endif %}
  76. <button type="button" data-role="none" class="slick-next" aria-label="{{ settings.nextArrow|t }}" tabindex="0">{{ settings.nextArrow|t }}</button>
  77. </nav>
  78. {% endblock %}
  79. {% endif %}
  80. </div>