We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Access current timestamp within a liquid template

Access current timestamp within a liquid template

matoow
Shopify Partner
15 1 9

I have stored some information in a customer's metafield.  I want to be able to apply a filter to this based on the current time, but it seems there is no way to access the current timestamp from within the liquid template.

 

The liquid template is cached, so this:-

{{ "now" | date: "%Y-%m-%d %H:%M" }}

will only give the last time the page was updated in the cache.

 

I was hoping that the current timestamp might be included as one of the template variables that's passed in.  Has anyone else had a similar issue and managed to work around it?

 

Thanks.

Reply 1 (1)

PaulNewton
Shopify Partner
8031 685 1646

@matoow wrote:

 I want to be able to apply a filter to this based on the current time


Generally solve this on the frontend with javascript.

Without apps you need to roundabout it on the clientside|frontend through an external clock possibly feeding it back through something like cart-attributes, but it varies wildly if that works for whatever the actual goal and factors are.

Contact paull.newton+shopifyforum@gmail.com for the solutions you need


Save time & money ,Ask Questions The Smart Way


Problem Solved? ✔Accept and Like solutions to help future merchants

Answers powered by coffee Thank Paul with a Coffee for more answers or donate to eff.org