A bit confused about TWIG and dynamic content in a page

Is there a way to use twig to add simple things to pages such as the current server time, or does all scripting (apart from javascript) have to be done in the templates? I know this is a super basic question but I’m still trying to wrap my mind around things. Thanks!

To use twig in a page you have to activate twig in that page.

See https://learn.getgrav.org/content/headers#process

Ok, then let’s say you wanted to use twig to add the date or time, what would the syntax be? I’m looking through a lot of documentation but having trouble finding an example.

Have you looked at the Twig documentation? Specifically the date function?

It would have been just as easy for you to give up the answer rather than pointing to the docs… The docs don’t have an entry, “Display the current date.” However thanks to the folks at stackoverflow who are all about easy answers I got a working expression:

{{ mydate|date(‘d/m/Y’) }}

I understand the idea of getting people to grok TWIG and all this stuff, but man, I’m just trying to get a project done, I don’t need a master’s degree. I’ll learn twig and related scripting languages the way I learn everything: bits and pieces at a time to accomplish what I’m trying to do at that time.

What would be cool and super helpful is to have an additional recipe page here with a bunch of simple twig expressions like the date thing above.

I didn’t mean to annoy you. The page I linked to does indeed have the answer: “If no argument is passed, the function returns the current date,” so date(). Teach people to fish and all that. No master’s degree needed.

At the risk of exacerbating things, there is a Twig cookbook. It doesn’t answer your specific question, to be fair.

Twig is really quit simple once you get the basics. The way I learned it originally (quite a few years ago!) was to go over the “Twig for Designers” Page. It’s one page that basically covers all the basics: http://twig.sensiolabs.org/doc/templates.html

I personally don’t like that the within our time everything is token as granted. I type in a question and want to have the right answer specifically to my needs as quick as possible.

There were times people had to go to libraries, maybe order very specific books or write letters to the people with such knowledge and hope they will have the time to answer…

Everything now is deadline and adrenaline and rubbish. Though, if I promise something where I don’t have the knowledge prior, it’s my risk and I’d only blame me.

Anyways, no offense, just monday and a coming deadline. :wink:

I’m a RTFM kinda guy. But documentation can be poorly organized or answers worded in ways that defy searching. When I ask a question on a forum, I’m quite content to be linked the correct point in the documentation. Once I have that, I can get other answers there, too, without bothering other people. Otherwise you keep coming up against walls and keep asking other people for their time. In this case, the documentation in question has only 4 sentences in it. The last one was the answer. It seemed reasonable to link to it because the answer was immediately apparent and I wasn’t sure the asker even knew where the documentation was. I wasn’t trying to be cheeky. Maybe I’m just an old man, but manners are still a thing to me. If someone takes time out of their own busy day to voluntarily reply to my question, I accept what they offer with gratitude and figure it out. I monitor the forums not because I have to but because I think Grav is a top-notch CMS and others were generous with their time when I needed it. Now back to my own day’s deadline…