Date visibility
Ability to show offers, events, etc... between specific dates
In the backoffice, you can schedule the starting and ending date for offers, events, news and blog items.
Before reading, make sure you are familiar with these 2 concept:
the helper GalaxyHelpers.staticSearch()
Legacy feature
The backend checks if the offer should be visible based on the start / end date and the current date. If an offer should not be visible, then it is considered offline: when doing a loop
, getting JSON for offers, etc.. the offer was not visible in the source code.
This is working fine on local website, because the page is built on page load.
On the live website, the visibility of an offer depends on the publication date. We serve static websites, after publication the source code of the website doesn't change.
The start / end date were more a "security" to prevent old / future offers from being visible, but you still had to republish if you wanted to show / hide an offer on the live website.
New feature
To be able to have offers show / hide based on the current date, the offers needs to be added in the page in Javascript (as the source code will not change on a live website)
Here is the new way it will work:
in the HTML, the page doesn't have the offer loops
in Javascript, the list of offers is fetched using
GalaxyHelpers.staticSearch()
. Behind the scene, this helper will filter the offers that should be visible or not based on the current date.in Javascript, when the promise resolves, using a JS templating language, you generate the HTML and append it to the page.
Prepare your theme
To prepare the activation of this feature, you first need to make changes to your theme:
You will need to replace:
For now, this won't change how the feature work. It only changes the way you get data.
When everything will be properly ready, we will enable the feature.
"loop" in the HTML to replace with JSON Static feature
Do not use on collection websites for now (documentation is not written yet and it requires some specific code)
1 - replace all loops for these module by getting data from json using static API with GalaxyHelpers.staticSearch()
It is very important to get the json with GalaxyHelpers.staticSearch()
, as the function will filter the offers to show only the ones that should be visible at the current date.
Also, be careful to check if at some places the theme uses / displays the "number of offers/news/events/blog"
For example, several themes use .nb_offers
How to find where these loops are used?
Page prev / next
On detail page, you can do a link to next item / previous item
If you don't change it, sometimes the link will lead to a 404 page. Using JS, you get the list of offers (JSON Static) and find the previous / next one.
Replace old ajax call
Some very old themes used to call "dynamic" to get asynchronously the offers / news / blogs / events. If this is the case, you need to replace it by JSON Static.
Menu built by Galaxy
Currently, there is no validated solution for the CMS Menu (automated menu based on the navbar in the backoffice).
If you enable the offer / news / event / blog page in the menu, all offers online on the date of the publish will be visible.
FAQ
Can I keep using a loop, add data-attributes to item and decide in JS to show / hide them?
We do not advise it as it would put a lot of code inside the DOM. Indeed, you can no longer use the "limit" filter of a loop.
For example if you have a block that shows the 3 first featured offers: all featured offers will need to be in the DOM. Indeed, if you get the "3 first offers" only in the DOM, you don't know if these 3 first will be visible or expired.
TODO - collection website
TODO - Use json line
Last updated