Toggle class in panel with select field

Hi there once again

I’m trying to set up a language switch toggler in the panel to control the visibility of the language switch on the front-end (language switch visible/not visible).

My template:
<div class="example-class example-class <?= $site->switch() ?>">

My blueprint:
switch:
label: Toggle Switch
type: select
options:
d-none: hidden
d-block: visible

  • d-none and d-block are standard bootstrap classes for display: none | block

Unfortunately it doesn’t work: after selecting and saving an option in the select field, the selection falls back to no selection and no impact is seen on the front end. The strange thing is, that a similar setup works for another page I’m working on currently. The problem occurs on a site, which was made in march 2015 and I updated recently to the newest Kirby Version but my feeling is still, that this may be an issue with an older component of the site.

Is anyone familiar with this kind of issue?

That’s probably due to the dash you use in your options that markdown doesn’t like. Wrap the keys in quotes:

"d-none": hidden

A - in my opinion - better alternative would be to conditionally render the switch instead of hiding it with classes. If someone views the site with styles disabled, the switch. would be visible.

Thanks, it wasn’t the dash but after it still confused me, that the selected field didn’t stay selected after saving the page I found the problem. It was due to activating language mode and the content file: I renamed the site.txt to site.de.txt and site.en.txt but had forgotten to delete the remaining site.txt. Sorry, my bad!

Ps. And thanks for your suggested solution but hiding with classes is fine for the moment.