You are here

block--diba-carousel.html.twig in Diba carousel slider 8

Default theme implementation for diba_carousel.

File

templates/block--diba-carousel.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Default theme implementation for diba_carousel.
  5. */
  6. #}
  7. <div{{ attributes.addClass(['block', 'diba-carousel']) }}>
  8. {{ title_prefix }}
  9. {% if label %}
  10. <h2{{ title_attributes }}>{{ label }}</h2>
  11. {% endif %}
  12. {{ title_suffix }}
  13. {% if elements.content.config.carousel_style == 'diba' %}
  14. {{ attach_library('diba_carousel/diba-style') }}
  15. {% endif %}
  16. {% block content %}
  17. {% set items_count = elements.content.items|length %}
  18. {% if items_count > 0 %}
  19. {% set items_by_slide = elements.content.config.items_by_slide %}
  20. {% set slides_count = (items_count/items_by_slide)|round(0, 'ceil') %}
  21. {% set data_interval = elements.content.config.data_interval %}
  22. {% if data_interval == 0 %}
  23. {% set data_interval = "false" %}
  24. {% endif %}
  25. <div id="{{ elements.content.id }}" class="carousel slide" data-ride="carousel" data-interval="{{ data_interval }}">
  26. {# Carousel indicators #}
  27. {% if slides_count > 1 and elements.content.config.show_indicators %}
  28. <ol class="carousel-indicators">
  29. {% for i in 0..slides_count-1 %}
  30. <li data-target="#{{ elements.content.id }}" data-slide-to="{{ i }}"{% if loop.first %} class="active"{% endif %}></li>
  31. {% endfor %}
  32. </ol>
  33. {% endif %}
  34. <div class="carousel-inner">
  35. {% set item_cols = 12 / items_by_slide %}
  36. {% set item_slide = 0 %}
  37. {# Carousel items #}
  38. {% for item in elements.content.items %}
  39. {% set item_slide = item_slide + 1 %}
  40. {# Open carousel slide #}
  41. {% if item_slide == 1 %}
  42. <div class="item carousel-item{% if loop.first %} active{% endif %}">
  43. {% endif %}
  44. {# Open carousel cols #}
  45. {% if items_by_slide > 1 %}
  46. {% if item_slide == 1 %}<div class="row carousel-row">{% endif %}
  47. <div class="col-sm-{{ item_cols }} carousel-col">
  48. {% endif %}
  49. {# Carousel image #}
  50. {% if item.image %}
  51. <img src="{{ file_url(item.image) }}" alt="{{ item.title|raw|striptags }}" width="{{ item.image_width }}" height="{{ item.image_height }}"{% if elements.content.config.image_class %} class="{{ elements.content.config.image_class }}"{% endif %}>
  52. {% endif %}
  53. {# Carousel captation #}
  54. <div class="carousel-caption">
  55. {% if item.title %}
  56. <h2 class="caption-title">
  57. {% if item.url %}
  58. {{ link(item.title|raw, item.url) }}
  59. {% else %}
  60. {{ item.title|raw }}
  61. {% endif %}
  62. </h2>
  63. {% endif %}
  64. {% if item.description %}
  65. <div class="caption-desc">{{ item.description|raw }}</div>
  66. {% endif %}
  67. </div>
  68. {# Close carousel cols #}
  69. {% if items_by_slide > 1 %}
  70. </div>
  71. {% if loop.last or item_slide >= items_by_slide %}</div>{% endif %}
  72. {% endif %}
  73. {# Close carousel slide #}
  74. {% if loop.last or item_slide >= items_by_slide %}
  75. </div>
  76. {% set item_slide = 0 %}
  77. {% endif %}
  78. {% endfor %}
  79. {# Carousel controls #}
  80. {% if slides_count > 1 and elements.content.config.show_controls %}
  81. <div class="carousel-controls">
  82. <a class="carousel-control-prev left carousel-control" href="#{{ elements.content.id }}" role="button" data-slide="prev">
  83. <span class="carousel-control-prev-icon glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
  84. <span class="sr-only">{% trans %}Previous{% endtrans %}</span>
  85. </a>
  86. <a class="carousel-control-next right carousel-control" href="#{{ elements.content.id }}" role="button" data-slide="next">
  87. <span class="carousel-control-next-icon glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
  88. <span class="sr-only">{% trans %}Next{% endtrans %}</span>
  89. </a>
  90. </div>
  91. {% endif %}
  92. </div>
  93. </div>
  94. {# Carousel more link #}
  95. {% if elements.content.config.more_link and elements.content.config.more_link_text %}
  96. <div class="carousel-more-link">
  97. {{ link(elements.content.config.more_link_text|t, elements.content.config.more_link, {'title': elements.content.config.more_link_text}) }}
  98. </div>
  99. {% endif %}
  100. {% endif %}
  101. {% endblock %}
  102. </div>