You are here

paragraph--bp-accordion.html.twig in Varbase Bootstrap Paragraphs 8.7

Bootstrap Paragraphs template for displaying an Accordion (Collapse).

Available variables:

  • paragraph: Full paragraph entity.

    • id: The paragraph ID.
    • bundle: The type of the paragraph, for example, "image" or "text".
    • authorid: The user ID of the paragraph author.
    • createdtime: Formatted creation date. Preprocess functions can reformat it by calling format_date() with the desired parameters on $variables['paragraph']->getCreatedTime().
  • content: All paragraph items. Use {{ content }} to print them all, or print a subset such as {{ content.field_example }}. Use {{ content|without('field_example') }} to temporarily suppress the printing of a given child element.
  • attributes: HTML attributes for the containing element. The attributes.class element may contain one or more of the following classes:

    • paragraphs: The current template type (also known as a "theming hook").
    • paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an "Image" it would result in "paragraphs--type--image". Note that the machine name will often be in a short form of the human readable label.
    • paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a preview would result in: "paragraphs--view-mode--preview", and default: "paragraphs--view-mode--default".
  • view_mode: View mode; for example, "preview" or "full".
  • logged_in: Flag for authenticated user status. Will be true when the current user is a logged-in member.
  • is_admin: Flag for admin user status. Will be true when the current user is an administrator.

File

templates/paragraph--bp-accordion.html.twig
View source
  1. {#
  2. /**
  3. * @file
  4. * Bootstrap Paragraphs template for displaying an Accordion (Collapse).
  5. *
  6. * Available variables:
  7. * - paragraph: Full paragraph entity.
  8. * - id: The paragraph ID.
  9. * - bundle: The type of the paragraph, for example, "image" or "text".
  10. * - authorid: The user ID of the paragraph author.
  11. * - createdtime: Formatted creation date. Preprocess functions can
  12. * reformat it by calling format_date() with the desired parameters on
  13. * $variables['paragraph']->getCreatedTime().
  14. * - content: All paragraph items. Use {{ content }} to print them all,
  15. * or print a subset such as {{ content.field_example }}. Use
  16. * {{ content|without('field_example') }} to temporarily suppress the printing
  17. * of a given child element.
  18. * - attributes: HTML attributes for the containing element.
  19. * The attributes.class element may contain one or more of the following
  20. * classes:
  21. * - paragraphs: The current template type (also known as a "theming hook").
  22. * - paragraphs--type-[type]: The current paragraphs type. For example, if the paragraph is an
  23. * "Image" it would result in "paragraphs--type--image". Note that the machine
  24. * name will often be in a short form of the human readable label.
  25. * - paragraphs--view-mode--[view_mode]: The View Mode of the paragraph; for example, a
  26. * preview would result in: "paragraphs--view-mode--preview", and
  27. * default: "paragraphs--view-mode--default".
  28. * - view_mode: View mode; for example, "preview" or "full".
  29. * - logged_in: Flag for authenticated user status. Will be true when the
  30. * current user is a logged-in member.
  31. * - is_admin: Flag for admin user status. Will be true when the current user
  32. * is an administrator.
  33. *
  34. * @see template_preprocess_paragraph()
  35. *
  36. * @ingroup themeable
  37. */
  38. #}
  39. {{ attach_library('varbase_bootstrap_paragraphs/vbp-default') }}
  40. {{ attach_library('varbase_bootstrap_paragraphs/vbp-colors') }}
  41. {{ attach_library('varbase_bootstrap_paragraphs/vbp-accordion') }}
  42. {# Background color. #}
  43. {% if content.bp_background|render %}
  44. {% set layout_background = content.bp_background['#items'].getString() %}
  45. {% set layout_background_classes = [ layout_background ] %}
  46. {% endif %}
  47. {# The template default set classes. #}
  48. {%
  49. set classes = [
  50. 'paragraph',
  51. 'paragraph--type--' ~ paragraph.bundle|clean_class,
  52. view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
  53. ]
  54. %}
  55. {# Merges Background color with classes. #}
  56. {% set background_field = content.bp_background|render %}
  57. {% if background_field %}
  58. {% set classes = classes|merge(layout_background_classes) %}
  59. {% endif %}
  60. {# No container by default. #}
  61. {% set add_container = false %}
  62. {# If there is BG image it's always edge to edge #}
  63. {% if (VBP.background_image.url or content.bp_background|render) %}
  64. {% set attributes = attributes.addClass('bg-edge2edge') %}
  65. {% set add_container = true %}
  66. {% endif %}
  67. {# If gutter option were selected. #}
  68. {% if VBP.bp_gutter.value %}
  69. {% set add_container = true %}
  70. {% endif %}
  71. {% if VBP.background_image.url %}
  72. {% set attributes = attributes.addClass('background-style') %}
  73. {% endif %}
  74. {# Sets Unique ID for Accordion from Paragraph ID. #}
  75. {% set paragraph_id = 'vbp-accordion-' ~ paragraph.id.value %}
  76. {# Sets paragraph title for paragraph. #}
  77. {% set paragraph_title = content.bp_title[0]['#context']['value']|render %}
  78. {# Sets paragraph title status for paragraph. #}
  79. {% set paragraph_title_status = true %}
  80. {% if VBP.bp_title_status.value %}
  81. {% set paragraph_title_status = false %}
  82. {% endif %}
  83. {# Add custom paragraph CSS class(es). #}
  84. {% if VBP.bp_classes.value %}
  85. {% set striped_custom_classes = VBP.bp_classes.value|striptags|lower %}
  86. {% set split_custom_classes = striped_custom_classes|split(' ') %}
  87. {% for custom_class in split_custom_classes %}
  88. {% set clened_custom_class = [ custom_class|clean_class ] %}
  89. {% set classes = classes|merge(clened_custom_class) %}
  90. {% endfor %}
  91. {% endif %}
  92. {# Prints Accordion template. #}
  93. <div{{ attributes.addClass(classes).setAttribute('id', paragraph_id) }} role="tablist" aria-multiselectable="true" {% if VBP.background_image.url %} style="background-image:url({{- VBP.background_image.url -}});" {% endif %}>
  94. {% if add_container %}<div class="container">{% endif %}
  95. <div class="row">
  96. <div class="{{- VBP.bp_width.value -}}">
  97. {% if paragraph_title and paragraph_title_status %}<h2 class="text-center">{% spaceless %}{{- paragraph_title|striptags -}}{% endspaceless %}</h2>{% endif %}
  98. {{ title_suffix }}
  99. <div class="card panel panel-default">
  100. {# Loop through all of the accordion sections. #}
  101. {% for key, item in content.bp_accordion_section if key|first != '#' %}
  102. {% set attributes = attributes.removeClass('bg-edge2edge') %}
  103. <div class="card-header panel-heading" role="tab" id="heading-{{ paragraph_id }}-{{ key + 1 }}">
  104. <div class="panel-title">
  105. <a data-toggle="collapse" data-target="#collapse-{{ paragraph_id }}-{{ key + 1 }}" href="#collapse-{{ paragraph_id }}-{{ key + 1 }}" aria-expanded="false" class="collapsed" aria-controls="collapse-{{ paragraph_id }}-{{ key + 1 }}">
  106. {# Print the accordion section title. #}
  107. {{ item['#paragraph'].bp_accordion_section_title.value }}
  108. </a>
  109. </div>
  110. </div>
  111. <div id="collapse-{{ paragraph_id }}-{{ key + 1 }}" class="card-block panel-collapse collapse" role="tabpanel" aria-labelledby="heading-{{ paragraph_id }}-{{ key + 1 }}">
  112. {# Loop through all of the accordion section bodies. #}
  113. {% for body_key, body_item in item['#paragraph'].bp_accordion_section_body %}
  114. {# Use the same render array as item and set the '#paragraph'. #}
  115. {% set section_body = item %}
  116. {# Get the language code #}
  117. {% set language = section_body['#paragraph'].langcode[0].value %}
  118. {# Check if a translation exists #}
  119. {% if section_body['#paragraph'].bp_accordion_section_body[body_key].entity.hasTranslation(language) %}
  120. {# Load the entity for the current translation #}
  121. {% set section_body = section_body|merge({'#paragraph': section_body['#paragraph'].bp_accordion_section_body[body_key].entity.getTranslation(section_body['#paragraph'].langcode[0].value)}) %}
  122. {% else %}
  123. {# Load the source entity #}
  124. {% set section_translation = section_body['#paragraph'].bp_accordion_section_body[body_key].entity %}
  125. {% endif %}
  126. {# Remove the cache keys so it doesn't repeat the first value. #}
  127. {% set section_body = section_body|merge({'#cache': {}}) %}
  128. {# Print the compiled section body. #}
  129. {{ section_body }}
  130. {% endfor %}
  131. </div>
  132. {% endfor %}
  133. </div>
  134. </div>
  135. </div>
  136. {% if add_container %}</div>{% endif %}
  137. </div>