Django-syntax like template-engine for Go
mymap["foo"]
or
myarray[0]
(#281).block.Super
won't be escaped anymore by default (#301).nil
is now supported in function calls (#277).Thanks to all contributors.
Changes in this long awaited release:
io.Writer
in Execute()
functions and short-circuit evaluations in expressionsTemplateSet.FromBytes
RenderTemplateBytes
Template.ExecuteWriterUnbuffered
TemplateLoader
interface and according functions for virtual filesystem support (incl. support for multiple loaders)pongo2.SetAutoescape
for a global behavior change{%-
and -%}
for tags and pongo2.Options
for blockspongo2.CleanCache
to remove files from the template cacheTemplate.ExecuteBlocks
to render supplied list of blocks onlySee https://github.com/flosch/pongo2/compare/v3.0...v4.0.0 for a full list of changes. Thanks to all contributors!
if_exists
-flag in include
-tagsorted
-flag in for
-tag with support for maps and arrays/slicesblock.Super
supportsplit
filterSee more in this blog post:
See this blog post for more about the pongo2 v3 release:
I'm happy to release the first major update for pongo2: v2. It got a lot of new features and bug fixes. Thanks to all reporters and contributors.
This release is backwards-incompatible to v1 which means chances are you have to adapt your codebase (slightly) in order to use v2. The pongo2 playground already uses pongo v2 (including the new features like sandboxing) and now got the official pongo2-addons
package enabled for testing and playing with pongo2. pongo2-addons
is already ready to use with pongo v2.
To install v2 and get backwards-compatible changes and bugfixes for later versions of the v2 series, use this import path:
Use this import path to stick with the latest development version of pongo2:
From*
are working on); see the DefaultSet
here. Features of the template sets include:
Debug
is set to true, logging of specific errors occur to stdout
(you can print out errors as well using the new ExecutionContext.Logf
function which will only print out your logging information when Debug
is true). Debug
has implications on the new template caching function as well (see below).include
, extends
or ssi
-tag, or outside templates when calling the From*()
-functions) was, in case of a relative path, to lookup the filename relative to the application's directory or, in case of an absolute path, to take this absolute one. It's now possible to change the base lookup directory (for relative paths) by using the new template set functions SetBaseDirectory()
and BaseDirectory()
.include
or outside of templates when using a function like From*()
). Use the attribute SandboxDirectories
to provide path patterns supported by http://golang.org/pkg/path/filepath/#Match in order to restrict the access to specifc files or directories. You can limit the tag/filter access by using the two new template set functions BanFilter
and BanTag
.FromCache
which behaves like FromFile
, but includes caching: FromCache
only compiles a template once per template (even if called multiple times) and can be called from multiple Goroutines (it's thread-safe). When debugging is activated (see above), FromCache will re-compile the given template on any request (simplifies development to see live changes).export
keyword to your macro declaration (like this: {% macro my_exported_macro(args1, args2="default string") export %}
). You can import exported macros by using the new import
tag: {% import "my_file_with_macros.html" my_exported_macro, another_exported_macro as renamed_macro %}
. Macros import macros (chaining macros) is supported.set
: Sets a variable to a given expression like this: {% set my_variable = 5 + 10 / another_var_number %}
reversed
argument for the for
-tagelif
-tag added (to support multiple cases when using the if
-tag)ReplaceTag
and ReplaceFilter
.pongo2.Value
as safe
(so the escape
filter won't get applied when outputting the value) using the new API-function AsSafeValue
. This reduces the necessary to apply the safe
filter manually, for example when using the markdown
filter from the pongo2-addons
package.Error
type which returns detailed machine-readable information (including the affected raw template line) about the error occurred and is now much more specific in some cases on which error occurredparsed
argument of the ssi
-tagINodeEvavluator
got replaced by IEvaluator
*Error
).See the whole changelog here: https://github.com/flosch/pongo2/compare/v1...v2
As always, I'm happy about any feedback!
I'm happy to announce pongo2 v1.0, the first stable release.
pongo2 aims to be compatible with Django 1.7 with regards to syntax, filters and tags. In combination with my official package pongo2-addons
pongo2 offers even more filters/tags including humanization and markup features.
All version 1.x releases will remain backwards compatible (only API improvements are possible, but no changes to any existing API functions/symbols). You can use the special import path
gopkg.in/flosch/pongo2.v1
to stick with version 1.x releases in your projects.
List of TODOs which could effect users of version 1.0:
verbatim
does not take a parameter yetblock.super
not supported yetValue.Iterate()
over strings is not utf-8 compatible yet (probably rarely used by users)Please also have a look on the caveats and on the development status hints when using pongo2.
pongo2 got a playground; feel free to play with it and to try pongo2 out.
I'm always glad about any feedback. I hope you enjoy this release!
I just finished the first release candidate for the first stable pongo2 version (1.0).