Django-syntax like template-engine for Go
pongo2 is a Django-syntax like templating-language (official website).
Install/update using go get (no dependencies required by pongo2):
go get -u github.com/flosch/pongo2/v7Please use the issue tracker if you're encountering any problems with pongo2 or if you need help with implementing tags or filters (create a ticket!).
:question: Looking for a Go developer/consultant? I'm available for hire. :man_technologist:
<html>
<head>
<title>Our admins and users</title>
</head>
{# This is a short example to give you a quick overview of pongo2's syntax. #}
{% macro user_details(user, is_admin=false) %}
{% endmacro %}
<body>
<h1>Our admins</h1>
{% for admin in adminlist %} {{ user_details(admin, true) }} {% endfor %}
<h1>Our members</h1>
{% for user in userlist %} {{ user_details(user) }} {% endfor %}
</body>
</html>date and time filter are taking the Golang specific time- and date-format (not Django's one) currently. Take a look on the format here.stringformat does not take Python's string format syntax as a parameter, instead it takes Go's. Essentially {{ 3.14|stringformat:"pi is %.2f" }} is fmt.Sprintf("pi is %.2f", 3.14).escape-filter is applied immediately. Therefore there is no need for a force_escape-filter yet.forloop fields (like forloop.counter) are written with a capital letter at the beginning. For example, the counter can be accessed by forloop.Counter and the parentloop by forloop.Parentloop.{% if key in map %}Key is in map{% else %}Key not in map{% endif %} or {% if !(key in map) %}Key is NOT in map{% else %}Key is in map{% endif %}.beego-pongo2, but for pongo2 v2.trans-tag implementation for internationalizationPlease add your project to this list and send me a pull request when you've developed something nice for pongo2.
I'm compiling a list of pongo2 users. Add your project or company!
Please see the documentation for a full list of provided API methods.
// Compile the template first (i. e. creating the AST)
tpl, err := pongo2.FromString("Hello {{ name|capfirst }}!")
if err != nil {
panic(err)
}
// Now you can render the template with the given
// pongo2.Context how often you want to.
out, err := tpl.Execute(pongo2.Context{"name": "florian"})
if err != nil {
panic(err)
}
fmt.Println(out) // Output: Hello Florian!…No open issues yet, or sync has not completed.