Forum

Thread tagged as: Question, Configuration, Suggestions

Trouble setting up course times

My site is now full powered with perch. So far so good :)

But I have one little issue: I would like to share the opening times on three different places on the whole site.

opening times

opening times

opening times

The first and second times on the images above are editable thru perch so far:

opening times

opening times

The third opening times are dynamically print for each day with php like the image below but unfortunately not editable thru perch:

opening times

My question is, how can I edit the dynamically rendered opening times thru perch like the two others like this?

<?php perch_content('Cocktailbar Montag'); ?>

Andreas Gücklhorn

Andreas Gücklhorn 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

PerchSystem::set_var('today', date('l'));
perch_content_custom('Offnungszeuten Cocktailbar', [
     'template' => 'course_time_cocktailbar.html',
]);

then in your template:

<perch:if id="today" value="Sunday">
    <perch:content id="sunday_times" type="text" label="Times for Sunday" />
</perch:if>
<perch:if id="today" value="Monday">
    <perch:content id="monday_times" type="text" label="Times for Monday" />
</perch:if>
<perch:if id="today" value="Tuesday">
    <perch:content id="tuesday_times" type="text" label="Times for Tuesday" />
</perch:if>

Is that what you mean?

(Screenshots of code are unhelpful, as I can't copy and paste the code to give you examples.)

I got this right now:

        <?php
        PerchSystem::set_var('today', date('l'));
        perch_content_custom('Zeiten Cocktailbar', [
        'template' => 'zeiten_cocktailbar.html',
        ]);
        ?>

and this is my template:

    <perch:if id="today" value="Sonntag">
    <perch:content id="sunday_cocktailbar" type="text" label="Sonntag" />
    </perch:if>

    <perch:if id="today" value="Montag">
    <perch:content id="monday_cocktailbar" type="text" label="Montag" />
    </perch:if>

    <perch:if id="today" value="Dienstag">
    <perch:content id="tuesday_cocktailbar" type="text" label="Dienstag" />
    </perch:if>

    <perch:if id="today" value="Mittwoch">
    <perch:content id="wednesday_cocktailbar" type="text" label="Mittwoch" />
    </perch:if>

    <perch:if id="today" value="Donnerstag">
    <perch:content id="thursday_cocktailbar" type="text" label="Donnerstag" />
    </perch:if>

    <perch:if id="today" value="Freitag">
    <perch:content id="friday_cocktailbar" type="text" label="Freitag" />
    </perch:if>

    <perch:if id="today" value="Samstag">
    <perch:content id="saturday_cocktailbar" type="text" label="Samstag" />
    </perch:if>

But there is no output :(

Drew McLellan

Drew McLellan 2638 points
Perch Support

What does this output:

<?php echo date('l'); ?>

Hey Drew,

I need to get this issue right. Please help me on this! Here is a mockup for the funktionality:

mockup

 <?php echo date('l'); ?>

gives the english day "friday"

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, than you shouldn't translate the perch:if conditions.

<perch:if id="today" value="Freitag">

should be

<perch:if id="today" value="Friday">

Still no output:

<perch:if id="today" value="sunday">
<perch:content id="sunday_cocktailbar" type="text" label="Sonntag" />
</perch:if>

<perch:if id="today" value="monday">
<perch:content id="monday_cocktailbar" type="text" label="Montag" />
</perch:if>

<perch:if id="today" value="tuesday">
<perch:content id="tuesday_cocktailbar" type="text" label="Dienstag" />
</perch:if>

<perch:if id="today" value="wednesday">
<perch:content id="wednesday_cocktailbar" type="text" label="Mittwoch" />
</perch:if>

<perch:if id="today" value="thursday">
<perch:content id="thursday_cocktailbar" type="text" label="Donnerstag" />
</perch:if>

<perch:if id="today" value="friday">
<perch:content id="friday_cocktailbar" type="text" label="Freitag" />
</perch:if>

<perch:if id="today" value="saturday">
<perch:content id="saturday_cocktailbar" type="text" label="Samstag" />
</perch:if>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Friday not friday.

Oh man, you are right! Now I got the output.

But it is now possible to combine the two regions like my mockup below?

mockup

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, you can use multiple templates to output the same content in different ways. Use the template option to specify which template to use where.