Read the statement by Michael Teeuw here.
Canteen-module // Mensa-Modul
-
@k-0
The “header” from the config is nothing but a html element.
You could leave the header column out of the module definition and include it separately in your .njk.
Then you would need it to be given a name by the user (via the config) since it is not thrown out by the API.Then just put a
tag above the rest and include the canteen name and a date. < header >{{ config.canteenName }}, {{ moment().format("dd, DD.MM.) }} < /header >
-
Hi @lavolp3 ,
i added
<header>{{ config.canteenName }}, {{ moment().format("dddd") }}</header>
to my MMM-Canteen.njk. But I always get “undefined”.
It works with
{{ config.canteenName }}
It seems there is a problem with moment() in the header. Do you have an idea?
-
@k-0 I am not 100% sure but I think moment() does not work in a nunjucks environment. So what I said above may have been very wrong, sorry!
I can’t test it now, but you can confirm the error with the moment() function by opening the mirror in your browser, then opening the developers console (F12) and looking in the console for an error thrown out by the template.
The nunjucks template works with
- usual html code
- variables you provide it with in the getTemplateData function
- filters (which are functions that need to be bound to functions in the main js file)
So what you can do is to include the variable in the getTemplatedata function
today: moment().format("dddd")
then call it in the template using
< header >{{ config.canteenName }}, {{ today }} < /header >
-
@lavolp3
Ah, i didn’t know this.Now it works with your example! :)
Unfortunately he takes the current date and not the date of the actual meal. (keyword: switchingTime). If and else apparently don’t work in the getTemplateData function. Or am I wrong?
-
@k-0 Of course they do. It is just a javascript function returning data that gets used by the nunjucks template.
This shortened and slightly more elegant if/else version should do the trick
today: (moment() < moment(this.config.switchTime, "HH:mm")) ? moment().format("dddd") : moment().add(1, "days").format("dddd")