Make styling easier

Created on 4 August 2025, about 2 months ago

Problem/Motivation

The slideshow appears inside a div.splide-wrapper, except if there's only one slide. This made it difficult to style.

Steps to reproduce

  1. Set an image field to display as a slideshow, with a nav
  2. Create pages some with 1 image, some with multiple
  3. Try to float the field right, or style it in some other way

Proposed resolution

Edit splide-wrapper.html.twig to put a div always. Add the splide-wrapper class only for a nav (else it breaks the library js).

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom adamps

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

Comments & Activities

  • Issue created by @adamps
  • 🇮🇩Indonesia gausarts

    Thank you.

    The only reason it was removed for a single slider is to have a DOM diet.

    However I understand a consistency might be needed somehow :)

    Currently, if this must be in, we must also change the references in splidebox which assumed splide-wrapper ONLY exists as an identifier for navigation. If it is always present, it will break:
    https://git.drupalcode.org/project/splidebox/-/blob/2.0.x/js/src/splideb...

    Perhaps we should replace it with splide-wrapper--nav to be more precise.

    Until then, you can copy the file into your theme if you don't use Splidebox, and adjust the HTML.

  • 🇬🇧United Kingdom adamps

    Thanks.

    I found that using splide-wrapper class without a nav already breaks the base splide library. I didn't fully understand it, but I guess it might be from splide.load.js line 143 if (!$.hasClass(p, ID + '-wrapper')) {. Maybe that code is specifically looking for splide-wrapper so won't like splide-wrapper--nav. Anyway I'm sure you will understand it much better than I do.

    Here's the template I ended up with. I skip the splide-wrapper class, but keep the others. I also added a class based on the optionset which is handy.

    {#
    /**
     * @file
     * Default theme implementation for a splide wrapper.
     *
     * Available variables:
     * - items: A list of items containing main and thumbnail of splide.html.twig
     *   which can be re-position using option Thumbnail position.
     * - attributes: HTML attributes to be applied to the list.
     * - settings: An array containing the given settings.
     *
     * @ingroup themeable
     */
    #}
    {%
      set classes = [
        settings.skin ? 'splide-wrapper--' ~ settings.skin|clean_class,
        settings.skin_nav ? 'splide-wrapper--' ~ settings.skin_nav|clean_class,
        settings.vertical ? 'is-wrapper-vertical',
        settings.vertical_nav ? 'is-wrapper-vertical--nav',
        'splide-wrapper--' ~ settings.optionset|clean_class,
        blazies.is.nav ? 'is-wrapper-nav',
        settings.navpos ? 'is-wrapper-nav--' ~ settings.navpos|clean_class,
        'over' in settings.navpos ? 'is-wrapper-nav--overlay',
        'over' in settings.navpos ? 'is-wrapper-nav--' ~ settings.navpos|replace({ 'over-' : '' })
      ]
    %}
    {%- if blazies.is.nav -%}
      {% set classes = classes|merge(['splide-wrapper']) %}
    {%- endif -%}
    
    <div{{ attributes.addClass(classes)|without('id') }}>
      {{- items -}}
    </div>
    
Production build 0.71.5 2024