60df20beada2495e19090435fe18a7dd3a128276
[yaffs-website] / templates / bootstrap / bootstrap-panel.html.twig
1 {#
2 /**
3  * @file
4  * Default theme implementation to display a Bootstrap Panel component.
5  *
6  * Available variables:
7  * - attributes: An array of HTML attributes intended to be added to the main
8  *   container tag of this template.
9  *   - id: A valid HTML ID and guaranteed to be unique.
10  * - body: The primary content of the panel.
11  * - body_attributes: (optional) Same as attributes, except applied to the body
12  *   container that appears in the template.
13  * - collapsible: Flag indicating whether the panel is collapsible.
14  * - collapsed: Flag indicating whether the panel is collapsed.
15  * - description: (optional) A list of description properties containing:
16  *    - content: (optional) A description of the form element, may not be set.
17  *    - attributes: (optional) A list of HTML attributes to apply to the
18  *      description content wrapper. Will only be set when description is set.
19  *    - position: (optional) A display setting that can have these values:
20  *      - before: The description is output before the element. This is the
21  *        default value.
22  *      - after: The description is output after the element.
23  *      - invisible: The description is output after the element, hidden
24  *        visually but available to screen readers.
25  * - errors: (optional) Any errors for panel, may not be set.
26  * - footer: (optional) Additional contents intended to be placed at the bottom.
27  * - footer_attributes: (optional) Same as attributes, except applied to the
28  *   footer container that appears in the template.
29  * - heading: (optional) The title of the panel, may not be set.
30  * - heading_attributes: (optional) Same as attributes, except applied to the
31  *   heading container that appears in the template.
32  * - panel_type: (optional) A contextual state. Will be one of these values:
33  *   - danger
34  *   - default (default value)
35  *   - info
36  *   - primary
37  *   - success
38  *   - warning
39  * - target: (optional) The target of the collapsible container.
40  *
41  * @ingroup templates
42  */
43 #}
44 {%
45   set classes = [
46     'panel',
47     errors ? 'panel-danger' : 'panel-' ~ panel_type|clean_class,
48   ]
49 %}
50 <div{{ attributes.addClass(classes) }}>
51
52   {# Heading #}
53   {% if heading %}
54     {% block heading %}
55       <div class="panel-heading">
56         {%
57           set heading_classes = [
58             'panel-title',
59             required ? 'form-required' : '',
60           ]
61         %}
62         {% if collapsible %}
63           <a{{ heading_attributes.addClass(heading_classes) }} href="{{ target }}">{{ heading }}</a>
64         {% else %}
65           <div{{ heading_attributes.addClass(heading_classes) }}>{{ heading }}</div>
66         {% endif %}
67       </div>
68     {% endblock %}
69   {% endif %}
70
71   {# Body #}
72   {% block body %}
73     {%
74       set body_classes = [
75       'panel-body',
76       collapsible ? 'panel-collapse',
77       collapsible ? 'collapse',
78       collapsible ? 'fade',
79       errors or collapsible and not collapsed ? 'in',
80       ]
81     %}
82     {%
83       set description_classes = [
84         'help-block',
85         description and description.position == 'invisible' ? 'sr-only',
86       ]
87     %}
88
89     {% if errors %}
90       <div class="alert alert-danger" role="alert">
91         <strong>{{ errors }}</strong>
92       </div>
93     {% endif %}
94
95     <div{{ body_attributes.addClass(body_classes) }}>
96       {% if description and description.position == 'before' %}
97         <p{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</p>
98       {% endif %}
99       {{ body }}
100       {% if description and description.position == 'after' or description.position == 'invisible' %}
101         <p{{ description.attributes.addClass(description_classes) }}>{{ description.content }}</p>
102       {% endif %}
103     </div>
104   {% endblock %}
105
106   {# Footer #}
107   {% if footer %}
108     {% block footer %}
109       {%
110         set footer_classes = [
111           'panel-footer',
112         ]
113       %}
114       <div{{ footer_attributes.addClass(footer_classes) }}>{{ footer }}</div>
115     {% endblock %}
116   {% endif %}
117
118 </div>