I need the current month or the next month to show.
I make this with a condition.
The result is right but in FLOW_CONTEXT Production Mode there is no change, when condition change.
prototype(Vendor.Site:Presentation.Offercard) < prototype(Neos.Fusion:Component) {
...
offermonth = Neos.Fusion:Case {
if {
condition = ${Date.dayOfMonth(Date.now()) <= 10} // Regel soll nur greifen, wenn Monatsanfang vom 1. bis 10.
aktmonth = ${Date.now()} // Setze aktuellen Monat.
aktmonthf = ${Date.format(this.aktmonth, 'm')}
renderer = ${this.aktmonthf}
}
else {
condition = ${Date.dayOfMonth(Date.now()) > 10 && Date.month(Date.now()) < 12} // Diese Regel soll greifen ab dem 11. des Monats, sofern nicht Dezember
nextmonth = ${Date.create('first day of next month')}
nextmonthf = ${Date.format(this.nextmonth, 'm')}
renderer = ${this.nextmonthf}
}
}
I suspect that the variable “offermonth” must be exempt from caching. But how should the line @cache.mode = ‘uncached’ be entered?
You cannot really exclude a single variable from cache.
You could however set the cache lifetime for this element to one day (or lower) so it gets refreshed regularly. Even better I guess would be to calculate this in the frontend via JS to avoid removing the cache that often.
I use the maximumLifeTime in the @cache configuration in the page footer which has a copyright notice with the current year - which has to automatically update on new years eve:
maximumLifetime = ${Date.create('first day of next year').timestamp - Date.now().timestamp}
You can alter that for the 11th of each month. It should be something like this…
maximumLifetime = ${Date.add(Date.create('first day of next month'), '11 days').timestamp - Date.now().timestamp}
That’s great!
I need this in my footer too.
I hadn’t thought about caching until now.
But now I was wondering how it worked for me that the year updated even though I had no longer touched an older neos project.
And in fact, now that I’ve checked I see that it still says 2022 in the footer. Oh man!
After a lot of trying, I patched together the following:
maxcachelifetime1 = ${Date.diff(Date.create('today'), Date.create('first day of next month'))}
maxcachelifetime = ${(this.maxcachelifetime1.d * 86400) + 950400}
I like your code (Especially the extension of the timestamp) and will try it.
Thank you for the concrete solution. I like copy and paste
(But before that I didn’t spare myself from working out a solution myself)