Skip to content

Instantly share code, notes, and snippets.

@yerminson
Forked from idiazroncero/container.html.twig
Last active April 28, 2020 16:50
Show Gist options
  • Save yerminson/a7f1183fe3cfc2cf66476ed841ac3eb5 to your computer and use it in GitHub Desktop.
Save yerminson/a7f1183fe3cfc2cf66476ed841ac3eb5 to your computer and use it in GitHub Desktop.
Drupal 8 // removes the [opinionated: unnecesary] class 'views-element-container' from rendered views.
{#
/**
* @file
* Theme override of a container used to wrap child elements.
*
* Used for grouped form items. Can also be used as a theme wrapper for any
* renderable element, to surround it with a <div> and HTML attributes.
* See \Drupal\Core\Render\Element\RenderElement for more
* information on the #theme_wrappers render array property, and
* \Drupal\Core\Render\Element\container for usage of the container render
* element.
*
* Available variables:
* - attributes: HTML attributes for the containing element.
* - children: The rendered child elements of the container.
* - has_parent: A flag to indicate that the container has one or more parent
containers.
*
* @see template_preprocess_container()
*/
#}
{%
set classes = [
has_parent ? 'js-form-wrapper',
has_parent ? 'form-wrapper',
]
%}
{% if attributes.hasClass('views-element-container') %}
{{ children }}
{% else %}
<div{{ attributes.addClass(classes) }}>{{ children }}</div>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment