Skip to content

Instantly share code, notes, and snippets.

@clrockwell
Created January 19, 2017 20:52
Show Gist options
  • Save clrockwell/90f330fb4a73cdfb49ede8cc4f080c00 to your computer and use it in GitHub Desktop.
Save clrockwell/90f330fb4a73cdfb49ede8cc4f080c00 to your computer and use it in GitHub Desktop.
{% set has_bg_colour = paragraph.field_background_colour.value %}
{#
We are going to check here if the paragraph bundle has a background colour
set. If so, we apply that background colour as a class on that paragraph bundle.
Then, if it has a background colour, we decide that we want to give it some
padding, so we also add a .has-bg class to it. If individual paragraph bundles
need to override that, we can use removceClass on their paragraph.html.twig files.
#}
{% if has_bg_colour|length > 0 %}
{% set bg_colour = has_bg_colour %}
{% set bg_padding = 'bg__padding' %}
{% endif %}
{% set id = paragraph.field_unique_id.value %}
{%
set classes = [
'paragraph',
'paragraph--type--' ~ paragraph.bundle|clean_class,
view_mode ? 'paragraph--view-mode--' ~ view_mode|clean_class,
bg_colour,
bg_padding,
]
%}
{% block content %}
<div id="{{ id }}" {{ attributes.addClass(classes) }}>
{{ content }}
</div>
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment