Last active
April 3, 2017 17:54
-
-
Save NikLP/1965b85fee55615fbea0c7cd164c44e2 to your computer and use it in GitHub Desktop.
Drop-in paragraph template to display fields as bootstrap accordian
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends "paragraph.html.twig" %} | |
{% block paragraph %} | |
<div{{ attributes.addClass('panel-group') }} id="accordion-{{ paragraph.id() }}" role="tablist"> | |
{% for field in content %} | |
{% set field_instance_items = [] %} | |
{% for key, field_instance in field if key|first != '#' %} | |
{% set field_instance_items = field_instance_items|merge([field_instance]) %} | |
{% endfor %} | |
{% if field_instance_items is not empty %} | |
<div class="panel panel-default"> | |
<div class="panel-heading" data-toggle="collapse" | |
data-parent="#accordion-{{ paragraph.id() }}" data-target="#collapse{{ loop.index }}"> | |
<h4 class="panel-title"> | |
<a> | |
{{ field['#title'] }} | |
</a> | |
</h4> | |
</div> | |
<div id="collapse{{ loop.index }}" class="panel-collapse collapse"> | |
<div class="panel-body"> | |
{{ field_instance_items }} | |
</div> | |
</div> | |
</div> | |
{% endif %} | |
{% endfor %} | |
</div> | |
{% endblock paragraph %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note
id="accordion-{{ paragraph.id() }}"
because potentially multiple per-page.Attribution:
For getting renderable field values out of {{ content }} @ http://drupal.stackexchange.com/a/208765/160
NB note about compatibility of collapse elements @ http://stackoverflow.com/questions/19236717/how-to-make-a-bootstrap-accordion-collapse-when-clicking-the-header-div
And of course, https://www.w3schools.com/bootstrap/bootstrap_collapse.asp