Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I can do it in PHP, but I'm having trouble converting it to twig.

Here's the PHP:

$day = date("l");
date_default_timezone_set('America/Chicago');



if ($day == "Saturday")
{
    echo "<p><b>SATURDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>Half priced desserts</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$1 off Seasonal Pints</h3>";

}
elseif ($day == "Sunday")
{
    echo "<p><b>GAMEDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>One Free Kids Meal w/ each Adult Meal</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$3 on ALL Bottled Beers</h3>";    }
elseif ($day == "Monday")
{
    echo "<p><b>MONDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>$1 Tenders <br />(5 piece min.)</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$2 Lonestar Pints</h3>";  }
elseif ($day == "Tuesday")
{
    echo "<p><b>TUESDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>$.50 Boneless Wings <br /> (10 piece min.)</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$4 Margaritas</h3>";  }
elseif ($day == "Wednesday")
{
    echo "<p><b>WEDNESDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>Half price APPs!</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$3 shots of Jameson & Jager</h3>";
}
elseif ($day == "Thursday")
{
    echo "<p><b>THURSDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>2 for $10 Wingzup Burgers</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$3 Draft Beers all day</h3>";
}
else
{
    echo "<p><b>FRIDAY SPECIALS</b></p>";
    echo "</div><div class=\"mod1\">";
    echo "<p>FOOD</p>";
    echo "<h3>$2 Chili Pies</h3>";
    echo "<p>DRINK</p>";
    echo "<h3>$10 Pitchers (Bud Lt./Ziegenbock/Lone Star)</h3>";
}
share|improve this question
    
You not gonna hardcode the daily menus into your template, Alex? –  carlcs Aug 18 at 17:01

1 Answer 1

To get the current date and time in Twig use the string "now" and filter it with the date() filter to return it in the format you need (see the list for supported parameters).

Then do the if / elseif conditionals similar to how you'd do it in PHP. Another option would be to use the Craft specific switch tag.

{% switch "now" | date("l") %}

    {% case "Monday" %}
        {# Do Monday stuff #}

    {% case "Tuesday" %}
        {# Do Tuesday stuff #}

    {% case "Wednesday" %}
        {# Do Wednesday stuff #}

    {# etc. #}

{% endswitch %}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.