Style switcher in panel

I hope this is not too much to ask: It would be nice to provide an option to quickly switch between two different stylesheets for a template, on the panel. For instance to exchange a dark font on a white background with a white font on a dark background, via a radiobutton or a toggle field. Of course I could just provide different templates to chose between but I wonder whether there is a simpler way to do it. Has anybody an idea?

Sure, you can use a toggle field in a blueprint and then include the stylesheet in your header snippet depending on that field value.

Ah, I figured it out, both with a checkbox and with a toggler.

Just if anybody else wants to do it:

In the blueprint add the following lines:

  label: Background
  type: checkbox
  text: Dark Background?

Then in the <head> section:

<?php if($page->background() == '1'): ?>
  <?php echo css('/assets/css/dark.css') ?>
<?php endif ?>

Looks good, but you could improve your template a bit to be more robust in the future:

<?php if($page->background()->bool()): ?>
  <?php echo css('assets/css/dark.css') ?>
<?php endif ?>
1 Like

Fine, I will do that, thanks!