GithubHelp home page GithubHelp logo

Comments (4)

flosch avatar flosch commented on June 4, 2024

You need to pass a time object to your template with a context and then you can use the date filter with it. See the caveats in the README regarding the format as it adheres to the Go time format.

from pongo2.

Peter2121 avatar Peter2121 commented on June 4, 2024

@flosch
Sorry, but caveats section in the README concerns the format to use. For me, time.Now() is a time object needed by the date filter. So I still don't see any evident reason why {{ time.Now()|date }} does not work. Please, put a link to an example explaining how to use time.Now() with time and date filters.

from pongo2.

flosch avatar flosch commented on June 4, 2024

Can you please show the context you're passing to your template? What is "time" in your template? There's no built-in symbol called "time". You could easily pass the current time (such as the result of time.Now() to a variable myTime in your context) and pass that variable to the date filter.

from pongo2.

Peter2121 avatar Peter2121 commented on June 4, 2024

There's no built-in symbol called "time".

OK, so this is a problem. Thank you.
In such case it seems to be impossible as I have no context, I render a simple pongo2 template with p2cli :

% cat test.j2
rendertime: {{ time.Now()|date }}
% p2 --template=test.j2
ERRO[0000] Failed to execute template: [Error (where: filter:date) | Line 1 Col 27 near 'date'] filter input argument must be of type 'time.Time'  output_path= source="main.go:458" template_path=
ERRO[0000] Errors encountered during template processing  source="main.go:465"

So, finally I used the tag now to produce the timestamp:

% cat test2.j2
rendertime: {% now "02-Jan-2006 15:04:05" %}
% p2 --template=test2.j2
rendertime: 01-Feb-2023 16:18:05

from pongo2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.