Answer the question
In order to leave comments, you need to log in
How would you implement such a mechanism?
Hello, how would you implement the following trick:
There is a site engine with a bunch of different texts, I want to be able to insert some bbcode-like labels into these texts
For example:
The label should be converted to a date according to the principle "now + 3 days" and cached on 3 days
That is, if today's date is
01/01/2019: Promotion valid until 01/03/2019
01/02/2019: Promotion valid until 01/03/2019
01/03/2019: Promotion valid until 01/03/2019
01/04/2019: Promotion valid until 01/07/2 caching is reset, add 3 days to today's number and cache for another 3 days
The problem is that there is absolutely no desire to use any database for this
Maybe someone will tell you how to implement this mathematically, without saving the start date somewhere in the database?
For example, the start date could be stored in the text field itself, and then dance from this number, calculating in what numbers you need to "reset the cache"
Tell me, please, can someone do something similar?
Answer the question
In order to leave comments, you need to log in
If you go crazy and don’t use a template engine on the backend, then just make a JS script that, using document.onload , will find tags with data-id=dateTmpl , get data from them and change their text.
Let's say there is a tag:
Promotion until
<span data-id="dateTmpl" data-start="10.09.2019" data-days="3"></span>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question