Forum
Using PHP in options-tag
I'm a frontend developer and have a bit struggle to implement my dynamically created opening hours in a radio-button template:
<perch:content id="course_time" type="radio" label="Do we have open today?" options="dynamically|<?php echo $cocktailbar; ?>, open|yes we have open, closed|no, we are closed" />
I have to print these times when the owner of the site choose the radio-button labeled with "dynamically":
<?php
$date = date('l');
switch ($date) {
case 'Sunday':
$cocktailbar = "Sonntag 18:00 – 22:30";
break;
case 'Monday':
$cocktailbar = "Heute ist die Bar geschlossen";
break;
case 'Tuesday':
$cocktailbar = "Heute ist die Bar geschlossen";
break;
case 'Wednesday':
$cocktailbar = "Heute ist die Bar geschlossen";
break;
case 'Thursday':
$cocktailbar = "Donnerstag 18:00 – 24:00";
break;
case 'Friday':
$cocktailbar = "Freitag 18:00 – 02:00";
break;
case 'Saturday':
$cocktailbar = "Samstag 18:00 – 02:00";
break;
}
?>
Is there a way to get this running?
If you wondering:
The restaurant owner need these options on holidays or other non regular days.
You cannot use PHP in a Perch template.
I'm not really sure what it is you are trying to achieve to be able to suggest a solution.
Hi Rachel :)
I got these website: https://www.seehofleineck.de/
On the upper left tile and the lower right tile there are dynamically rendered opening hours.
Now, I would like to use a perch radio button template with the following options available:
1: I will use the dynamically rendered opening hours from my php
2: Today is closed (because of an holiday or something else)
3: Today is open (because of a big party or whatever)
In your template:
Then in your page:
Hello Drew,
thank you so much for that awesome support!
Unfortunately, it doesn't work as expected. All three options are displayed right now:
You can remove
<?php perch_content('Foo'); ?>
as you've replace it with theperch_content_custom()
call.What does your template look like?
I removed the perch_content('Foo'). But all three options are still visible:
Replace
with
That was my late night typo that I then copied and pasted twice. Sorry!
Now it works like expected :)
Great product and great support, thanks!