Comments (4)
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.
@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.
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.
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)
- Cannot using template.Fromfile HOT 1
- Context key invalid HOT 1
- How to convert golang array to javascript array HOT 1
- Why this is no document about how to use it ?? HOT 8
- Struct field names in templates / contexts
- Data race in `pongo2.FromFile()` method HOT 5
- Potential security issue HOT 3
- Array in yml file as context is not supported
- Macro that invokes other macros does not work when imported HOT 1
- Not compatible with GCCGO 13.0.0 HOT 1
- How can pongo2 does not escape chars which except TokenSymbols?
- Bug: random order for `for` loop. HOT 2
- Include statement doesn't work inside for loop
- Returning only a partial block
- Potential BC break on master (missing var comparison)
- BC break between v4 and v6 (string/num adding/concatenating)
- question about split filter on new line
- need strings function HOT 1
- What tags deos pongo uses of declared structs struct?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pongo2.