Content-Change by Radio Button

I would like to change the content of a single page (e.g. a picture oder a CSS manipulation) by a radio button or similar in the backend.

Has anyone an idea how to manage this?

Cheers, Daniel :slight_smile:

Yes, you can query the value of the radio button field and then act upon that:

<?php 
if($page->radiofield()->bool()): 
// show an image or apply a class to an element
else:
// do something else
endif;
?>
1 Like

Good mordning!

I was experimenting with this code now for a long time. Unfortunately it was not successful.

Is there anywhere an example from what I probaply could leard how to handle this code?

Have a nice day, Daniel :slight_smile:

Just set a radio field (or several) in your blueprint, and then in the template do what @texnixe describes, or you can do it this way:

<body <?php if ($page->radiofield()->bool()): ?>class="yourclass"><?php endif ?> >

Just change radiofield() to the name of your field. A toggle field will work too.

Could you please post what you have in your blueprint?

And what you have in your template so far…

In my blueprint

category:
label: Category
type: radio
options:
test1: test 1
test2: test 2
test3: test 3
test4: test 4

In my html

<?php if ($page->category()->test1()): ?>Hallo<?php endif ?>

In the meantime I was trying everything, but nothing works. I can see the radio buttons in the panel but I never read the word hello on the website when choosing radio button test 1.

<?php if ($page->category() == 'test1'): ?>
Hallo
<?php endif ?>

You have to check if the value equals a given value.

If this doesn’t work, use $page->category()->value()

THANK U !!
:slight_smile:

1 Like