Add a class depending on a toggle field setting

Hi!

I tried to delete a class via the toggle option.
This is my blueprint:

fields:
  toggledeleteclass:
    label: Delete padding
    type: toggle

And this is my snippet for the template.

<?php if($page->toggledeleteclass()->bool()): ?>
    <div class="price price-margin-top">
      Here is my pricing table (deleted the whole pricing table)
    </div> 
<?php endif ?>

But then it shows the complete div if the toggle is true. I want to delete the class "price-margin-top’ if the toggle is set tue true. I tried already to do the loop around the class element but this seems not to work.

<div class="price <?php if($page->toggledeleteclass()->bool()): ?>price-margin-top"<?php endif ?>>
  Here is my pricing table (deleted the whole pricing table)
</div> 

Does anybody know how I can achieve this?

Thanks!

Use the e() helper…

<div class="price <?php e($page->toggledeleteclass()->bool(), 'price-margin-top')">

Reference help here.

The if statement in your examples above, i think should have worked though, if you move the closing qoute after the endif statement.

1 Like

Thank you! I get unfortunately a error:

ParseError
syntax error, unexpected '"'

Did you use the e() helper, or fix your if statement? I would try the e() helper, its more concise.

I tried your suggestion.

<div class="price <?php e($page->toggledeleteclass()->bool(), 'price-margin-top')">

Oh, sorry my bad i didnt close the PHP…

<div class="price <?php e($page->toggledeleteclass()->bool(), 'price-margin-top') ?> ">

Its Saturday, i may have had :beer:

1 Like

The closing php tag is missing:

<div class="price <?php e($page->toggledeleteclass()->bool(), 'price-margin-top') ?>">

Too late…:sleeping:

1 Like

Ooops I didn’t see it either.

Thanks you both!

You got the solution tag though so not all bad … :cry:

1 Like

Don’t be sad :hugs:

1 Like

:partying_face:

1 Like

Now you have it :wink: Cheers!

1 Like

:joy:

1 Like

Lol… .thanks @portobien … have fun with Kirby :slight_smile:

1 Like

Thanks!

This helped a lot! Thank you very much!