The layouts of WXP Opening Times are Twig templates. This guide lists the templates, the values they receive and how to make your own. For an introduction to Twig and the lookup order, see General Developer Information → Twig.
Templates #
| File | Name | What it shows |
|---|---|---|
default.html.twig |
Default | The status line and a table with the hours of the week. |
compact.html.twig |
Compact | One line: the status and the hours of today. No week table. |
grouped.html.twig |
Grouped days | Like the default, but days that follow each other and have the same hours share a line, such as “Monday to Thursday”. |
_base.html.twig |
Partial | The wrapper that all templates extend. It holds the data attributes that the script and the stylesheet need. |
_status.html.twig |
Partial | The open or closed badge and the summary. |
_nav.html.twig |
Partial | The buttons to browse to the next and the previous week. |
Use the name of the file without .html.twig in the template parameter of the shortcode, the block or the widget. A name that does not exist falls back to default.
Your own template #
{# Template Name: My hours #}
{% extends '_base.html.twig' %}
{% block body %}
{% if options.show_status %}
{% include '_status.html.twig' %}
{% endif %}
<ul>
{% for day in week.days %}
<li{% if day.today %} class="is-today"{% endif %}>
{{ day.name }}: {{ day.open ? day.text : closed }}
</li>
{% endfor %}
</ul>
{% endblock %}
- Save it as
my-hours.html.twiginwxp-opening-times/in your child theme and usetemplate="my-hours". - The line
Template Name:in the comment is the name shown in the template lists of the block and the widget. - Keep the content in
{% block body %}. When a visitor browses to another week or the status changes, only this block is rendered again and replaced. - Keep
{% extends '_base.html.twig' %}: it carries the attributes that the script uses.
Values in the templates #
| Name | Contents |
|---|---|
status |
open (true or false), badge, summary, closes_at, opens_at, next_change. |
today |
The day of today, with the same fields as a day in week.days. |
week |
offset, label (for example “3 Nov – 9 Nov”), days (seven days) and groups (days with the same hours, for the grouped template). |
week.days[] |
date, name, date_label, today, open, slots (each with open, close and text), text (all slots as one text), exception, source and label. |
week.groups[] |
name (such as “Monday to Thursday”), date_label, days (how many), today, open, slots, exception and label. |
schedule |
id and name. |
closed |
The text for a closed day. |
options |
show_status, week_nav, show_title, show_dates, weeks_ahead, heading_level and offset. |
labels |
Translated texts. |
template, box_id, generated |
The name of the template, a unique id for this block on the page, and the time of rendering. |
Add your own values with the filter wxp_opening_times_template_context (see Filter- and action hooks).