New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

Check which day of the week it is and add class accordingly.

Kaz van Kooten April 4, 2019 by Kaz van Kooten

Alright, here we go. I need to show opening hours on a website that's currently in development.

I have a nice little ul showing the days of the week:

Monday: 09:00am - 05:00pm

Tuesday: 09:00am - 05:00pm

And so on.

What I'd like to do is add a class to the li if it's currently that day, so that on Tuesdays the line reading "Tuesday: ..." is highlighted.

Something like:

<ul>
{{ opening_hours }}

  <li class="item {{ if something }} highlight {{ /if }}">
    {{ day }}: {{ hours }}
  </li>

{{ /opening_hours }}
</ul>

Is there a way to do this with nifty if/else antlers, or should I start dusting off my PHP snippets?

Thanks!

Answered by Daniel Saksa!
>>>>>>> Answered <<<<<<<
3 Replies
3 Followers