Showing text based on yes/no conditionals

Hi all -

I have a a yes/no toggle that I need to show in the front end, and I’m not sure of the correct syntax (php learner).

I’m using structured fields and my blueprint for this particular item is:

        label: Sold?
        type: toggle
        text: yes/no

I won’t even show my code as it would be embrassing no doubt, but I’d like to show ‘Sold’ if false and ‘Available’ if true. (if availability == true then ‘available’ else ‘sold’.)


<?= $page->availability()->bool()? 'available': 'sold'; ?>

Or more verbose with a standard if statement:

if($page->availability()->bool()) {
echo "The item is available";
} else {
echo "The item is out of stock";

Thanks. But both examples give me a ‘sold out’ message, no matter if I change it to true or false in the panel.

Ah, ok, your field is within a structure, so $page does not make sense, of course, you would have to adapt that to fit your code, i.e. whatever variable you are using within your foreach loop.

BTW. Could you please use the question category for questions? Makes it easier to keep track. Thanks.

Oops thanks, and oops sorry!