Use filter output as variable value

Trying to set a page element to only show within working hours.

Currently attempting to set the current day of week as a variable so I can then use it in an if statement to say “if Day of Week is in [1,2,3,4,5]”

{% set dowcur = {{ content.updated | format_date(‘e’) }} %}

When I use the above, I get the following error:

encountered ‘}’, expected ‘:’

Any ideas?

Hi @Sint0, You can use the HubL Date Filter to get the current day of the week and use that in an if statement to show or hide your page element.

For example, if you want to show the page element only between Monday and Friday, you can use the following code:

{% set dowcur = content.updated | format_date(‘e’) %}
{% if dowcur in [1, 2, 3, 4, 5] %}
<!-- Page element code here -->
{% endif %}

Alternatively, you can use the HubL Time Filter to check the current time and compare it to the opening and closing hours of your business.

For example, if you want to show the element between 9am and 5pm, you can use the following code:

{% set curtime = content.updated | format_date(‘H’) %}
{% if curtime >= 9 and curtime <= 17 %}
<!-- Page element code here -->
{% endif %}

For more information about using the HubL Date and Time Filters, please refer to the HubSpot Documentation: HubL filters - HubSpot docs
Hope this helps. Cheers! :slightly_smiling_face: