Hi, has anyone ever tried to use liquid code to hide a page element X amount of dates after “Release Date”.
Fore example: hide an image tag within a custom module item 365 days after the item has been released?
Thank you in advance.
Hi, has anyone ever tried to use liquid code to hide a page element X amount of dates after “Release Date”.
Fore example: hide an image tag within a custom module item 365 days after the item has been released?
Thank you in advance.
You can use Liquid date filters to achieve this:
{% assign current_time = "now" | date: "s" | plus: 0 %}
{% assign withdraw_time = this.ReleaseDate | date_add: 365, "day" | date: "s" | plus: 0 %}
{% if current_time < withdraw_time %}
Content here will display until the `withdraw_time` is reached.
{% endif %}
This is a similar approach to this Treehouse code snippet:
Adam, thank you. I did test both but could not get either to work.
My apologies Erik.
I missed the %
character in the | date: "%s"
filter.
Please update these 2 lines:
{% assign current_time = "now" | date: "%s" | plus: 0 %}
{% assign withdraw_time = this.ReleaseDate | date_add: 365, "day" | date: "%s" | plus: 0 %}
You are a legend! Thank you!