Created
October 21, 2016 17:54
-
-
Save thejimbirch/2cc2c8b5c80d4be8ceb16b23f47ec181 to your computer and use it in GitHub Desktop.
Drupal 8 Template for Bootstrap Paragraphs customized for Carousel.
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
{# | |
/** | |
* @file | |
* Bootstrap Paragraphs template for displaying a Carousel. | |
* | |
* 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. | |
* | |
* @see template_preprocess_paragraph() | |
* | |
* @ingroup themeable | |
*/ | |
#} | |
{{ attach_library('bootstrap_paragraphs/bootstrap-paragraphs') }} | |
{# Renders Width field. #} | |
{# Sets class name from values in database. #} | |
{% if content.field_width|render %} | |
{% set layout_width = content.field_width['#items'].getString() %} | |
{% set layout_width_classes = [ | |
'paragraph--width--tiny' == layout_width ? 'paragraph--width--tiny', | |
'paragraph--width--narrow' == layout_width ? 'paragraph--width--narrow', | |
'paragraph--width--medium' == layout_width ? 'paragraph--width--medium', | |
'paragraph--width--wide' == layout_width ? 'paragraph--width--wide', | |
'paragraph--width--full' == layout_width ? 'paragraph--width--full', | |
] | |
%} | |
{% endif %} | |
{# Renders Background field. #} | |
{# Sets class name from values in database. #} | |
{% if content.field_background|render %} | |
{% set layout_background = content.field_background['#items'].getString() %} | |
{% set layout_background_classes = [ | |
'paragraph--color paragraph--color--rgba-black-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-black-slight', | |
'paragraph--color paragraph--color--rgba-black-light' == layout_background ? 'paragraph--color paragraph--color--rgba-black-light', | |
'paragraph--color paragraph--color--rgba-black-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-black-strong', | |
'paragraph--color paragraph--color--rgba-blue-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-black-strong', | |
'paragraph--color paragraph--color--rgba-blue-light' == layout_background ? 'paragraph--color paragraph--color--rgba-blue-light', | |
'paragraph--color paragraph--color--rgba-blue-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-blue-strong', | |
'paragraph--color paragraph--color--rgba-bluegrey-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-bluegrey-slight', | |
'paragraph--color paragraph--color--rgba-bluegrey-light' == layout_background ? 'paragraph--color paragraph--color--rgba-bluegrey-light', | |
'paragraph--color paragraph--color--rgba-bluegrey-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-bluegrey-strong', | |
'paragraph--color paragraph--color--rgba-brown-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-brown-slight', | |
'paragraph--color paragraph--color--rgba-brown-light' == layout_background ? 'paragraph--color paragraph--color--rgba-brown-light', | |
'paragraph--color paragraph--color--rgba-brown-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-brown-strong', | |
'paragraph--color paragraph--color--rgba-cyan-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-cyan-slight', | |
'paragraph--color paragraph--color--rgba-cyan-light' == layout_background ? 'paragraph--color paragraph--color--rgba-cyan-light', | |
'paragraph--color paragraph--color--rgba-cyan-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-cyan-strong', | |
'paragraph--color paragraph--color--rgba-green-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-green-slight', | |
'paragraph--color paragraph--color--rgba-green-light' == layout_background ? 'paragraph--color paragraph--color--rgba-green-light', | |
'paragraph--color paragraph--color--rgba-green-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-green-strong', | |
'paragraph--color paragraph--color--rgba-grey-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-grey-slight', | |
'paragraph--color paragraph--color--rgba-grey-light' == layout_background ? 'paragraph--color paragraph--color--rgba-grey-light', | |
'paragraph--color paragraph--color--rgba-grey-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-grey-strong', | |
'paragraph--color paragraph--color--rgba-indigo-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-indigo-slight', | |
'paragraph--color paragraph--color--rgba-indigo-light' == layout_background ? 'paragraph--color paragraph--color--rgba-indigo-light', | |
'paragraph--color paragraph--color--rgba-indigo-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-indigo-strong', | |
'paragraph--color paragraph--color--rgba-lime-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-lime-slight', | |
'paragraph--color paragraph--color--rgba-lime-light' == layout_background ? 'paragraph--color paragraph--color--rgba-lime-light', | |
'paragraph--color paragraph--color--rgba-lime-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-lime-strong', | |
'paragraph--color paragraph--color--rgba-orange-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-orange-slight', | |
'paragraph--color paragraph--color--rgba-orange-light' == layout_background ? 'paragraph--color paragraph--color--rgba-orange-light', | |
'paragraph--color paragraph--color--rgba-orange-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-orange-strong', | |
'paragraph--color paragraph--color--rgba-pink-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-pink-slight', | |
'paragraph--color paragraph--color--rgba-pink-light' == layout_background ? 'paragraph--color paragraph--color--rgba-pink-light', | |
'paragraph--color paragraph--color--rgba-pink-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-pink-strong', | |
'paragraph--color paragraph--color--rgba-purple-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-purple-slight', | |
'paragraph--color paragraph--color--rgba-purple-light' == layout_background ? 'paragraph--color paragraph--color--rgba-purple-light', | |
'paragraph--color paragraph--color--rgba-purple-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-purple-strong', | |
'paragraph--color paragraph--color--rgba-red-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-red-slight', | |
'paragraph--color paragraph--color--rgba-red-light' == layout_background ? 'paragraph--color paragraph--color--rgba-red-light', | |
'paragraph--color paragraph--color--rgba-red-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-red-strong', | |
'paragraph--color paragraph--color--rgba-stylish-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-stylish-slight', | |
'paragraph--color paragraph--color--rgba-stylish-light' == layout_background ? 'paragraph--color paragraph--color--rgba-stylish-light', | |
'paragraph--color paragraph--color--rgba-stylish-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-stylish-strong', | |
'paragraph--color paragraph--color--rgba-teal-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-teal-slight', | |
'paragraph--color paragraph--color--rgba-teal-light' == layout_background ? 'paragraph--color paragraph--color--rgba-teal-light', | |
'paragraph--color paragraph--color--rgba-teal-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-teal-strong', | |
'paragraph--color paragraph--color--rgba-white-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-white-slight', | |
'paragraph--color paragraph--color--rgba-white-light' == layout_background ? 'paragraph--color paragraph--color--rgba-white-light', | |
'paragraph--color paragraph--color--rgba-white-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-white-strong', | |
'paragraph--color paragraph--color--rgba-yellow-slight' == layout_background ? 'paragraph--color paragraph--color--rgba-yellow-slight', | |
'paragraph--color paragraph--color--rgba-yellow-light' == layout_background ? 'paragraph--color paragraph--color--rgba-yellow-light', | |
'paragraph--color paragraph--color--rgba-yellow-strong' == layout_background ? 'paragraph--color paragraph--color--rgba-yellow-strong', | |
'paragraph--color--transparent' == layout_background ? 'paragraph--color--transparent', | |
'paragraph--color paragraph--color--primary' == layout_background ? 'paragraph--color paragraph--color--primary', | |
'paragraph--color paragraph--color--secondary' == layout_background ? 'paragraph--color paragraph--color--secondary', | |
'paragraph--color paragraph--color--success' == layout_background ? 'paragraph--color paragraph--color--success', | |
'paragraph--color paragraph--color--info' == layout_background ? 'paragraph--color paragraph--color--info', | |
'paragraph--color paragraph--color--warning' == layout_background ? 'paragraph--color paragraph--color--warning', | |
'paragraph--color paragraph--color--danger' == layout_background ? 'paragraph--color paragraph--color--danger', | |
] | |
%} | |
{% endif %} | |
{# Renders Slide Interval field. #} | |
{# Converts database values to classes supplied by template. #} | |
{% if content.field_slide_interval|render %} | |
{% set slide_interval = content.field_slide_interval['#items'].getString() %} | |
{% set slide_interval_classes = [ | |
'false' == slide_interval ? 'false', | |
'1000' == slide_interval ? '1000', | |
'2000' == slide_interval ? '2000', | |
'3000' == slide_interval ? '3000', | |
'4000' == slide_interval ? '4000', | |
'5000' == slide_interval ? '5000', | |
'6000' == slide_interval ? '6000', | |
'7000' == slide_interval ? '7000', | |
] | |
%} | |
{% endif %} | |
{# The template default set classes. #} | |
{% | |
set classes = [ | |
'paragraph', | |
'paragraph--type--' ~ paragraph.bundle|clean_class, | |
view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class, | |
'carousel', | |
'slide', | |
] | |
%} | |
{# Merges Width field with classes. #} | |
{% set width_field = content.field_width|render %} | |
{% if width_field %} | |
{% set classes = classes|merge(layout_width_classes) %} | |
{% endif %} | |
{# Merges Background field with classes. #} | |
{% set background_field = content.field_background|render %} | |
{% if background_field %} | |
{% set classes = classes|merge(layout_background_classes) %} | |
{% endif %} | |
{# Sets Unique ID for Carousel from Paragraph ID. #} | |
{% set paragraph_id = 'myCarousel-' ~ paragraph.id.value %} | |
{# Prints Carousel template. #} | |
{{ content|without('field_slide_content','field_slide_interval', 'field_width', 'field_background') }} | |
<div{{ attributes.addClass(classes).setAttribute('id', paragraph_id).setAttribute('data-interval', slide_interval_classes).setAttribute('data-ride', 'carousel') }}> | |
<ol class="carousel-indicators"> | |
{% for key, item in content.field_slide_content if key|first != '#' %} | |
<li class="{% if loop.first %}active{% endif %}" data-slide-to="{{ key }}" data-target="#{{ paragraph_id }}"></li> | |
{% endfor %} | |
</ol> | |
<div class="carousel-inner" role="listbox"> | |
{% for key, item in content.field_slide_content if key|first != '#' %} | |
<div class="paragraph--layout-slideshow__slide-{{ key + 1 }} item carousel-item{% if loop.first %} active{% endif %}">{{ item }}</div> | |
{% endfor %} | |
</div> | |
<a class="left carousel-control" href="#{{ paragraph_id }}" role="button" data-slide="prev"> | |
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> | |
<span class="sr-only">Previous</span> | |
</a> | |
<a class="right carousel-control" href="#{{ paragraph_id }}" role="button" data-slide="next"> | |
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> | |
<span class="sr-only">Next</span> | |
</a> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment