Provide Layout Templates with a variable to indicate they are in layout mode

Created on 26 April 2019, about 5 years ago
Updated 17 April 2024, about 2 months ago

Problem/Motivation

Realized when trying to drag blocks into a custom layout that some of my CSS classes cause havoc in the layout builder mode.

→

landing-banner.html.twig

{% if content %}
  <div{{ attributes.addClass('landing-banner') }}>
    {% if content.image %}
      <div{{ region_attributes.title.addClass('layout__region', 'landing-banner__image', 'extend–background') }}>
        {{ content.image }}
      </div>
    {% endif %}
    {% if content.title %}
      <div{{ region_attributes.title.addClass('layout__region', 'landing-banner__title') }}>
        {{ content.title }}
      </div>
    {% endif %}
  </div>
{% endif %}

Proposed resolution

Add a variable in_layout_builder or something using the routing context potentially to let the templates know where they are and they can remove/add classes as needed to fix this up.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

✨ Feature request
Status

Postponed

Version

11.0 🔥

Component
Layout builder  →

Last updated about 14 hours ago

Created by

🇨🇦Canada joelpittet Vancouver

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand DanielVeza Brisbane, AU

    This can check if the current route is using layout builder with code like this stripped back example

    $parameters = $this->routeMatch->getParameters();
    if ($parameters->has('section_storage')) {
      if ($parameters->get('section_storage') instanceof SectionStorageInterface) {
        return TRUE;
      }
    return FALSE;
    }
    

    Then in a preprocess you can add a class if that returns TRUE.

    I'm -1 of building something like this into core, I think it's something that can be quite easily added on a site by site basis, or it could be a contrib module.

    Postponing for others to give thoughts

Production build 0.69.0 2024