Conditional display based on select box active option


I’d like to be able to select the position of the logo on the site from the backend. So i created a sitewide select field with three options : Logo left, logo right, logo center.

Now on the front end i have diffenrent shunk of html that will or will not be displayed depending on the select box value… (left, right or center). But i can’t manage to achieve that because i have no idea how to make a conditional depending on a select box field value. Here is my code so far…

Sorry code doesn’t work on this forum, i d’ont understand why there is’nt a way to paste raw code…

Ideally this excerpt of code would have displayed the Logo HTML if the select field value is “left”. If the value is anything but left, doesn’t display anything. I would have used the exact same logic to display the html code at the right position for the logo to be right or centered…

You can paste small bits of code in the text box using these:`Preformatted text`. You can also prefix slightly larger bits with four spaces to make it look like this:

<p>this has four spaces</p>

Otherwise, paste your code somewhere like and put a link :slight_smile:

Apart. from. that, you can get the value of the field like this:

$activeOption = $page->field();
if($activeOptions === 'left'):  ?>
   <!--  your html code -->
<?php else: ?>
  <!--  other html code -->
<?php endif ?>

Or use elseif() if you need other options.

But depending on. your code, instead of using different HTML, just add. a class based on the select field value and do the rest with your CSS.

1 Like

Thanks it’s working !