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

Created on 26 April 2019, about 6 years ago
Updated 20 June 2024, 11 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

Closed: duplicate

Version

11.0 🔥

Component
Layout builder 

Last updated 1 day 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

  • 🇨🇦Canada joelpittet Vancouver

    Closing as a duplicate for this issue (thanks @larowlan and @eclipsegc)
    #3273317: Add 'in_preview' variable to block and layout templates

  • Status changed to Closed: duplicate 11 months ago
Production build 0.71.5 2024