{"id":13367047,"url":"https://github.com/flosch/ponGo2","last_synced_at":"2025-03-12T18:31:52.000Z","repository":{"id":10214981,"uuid":"12311467","full_name":"flosch/pongo2","owner":"flosch","description":"Django-syntax like template-engine for Go","archived":false,"fork":false,"pushed_at":"2024-08-14T05:43:02.000Z","size":713,"stargazers_count":2872,"open_issues_count":70,"forks_count":270,"subscribers_count":68,"default_branch":"master","last_synced_at":"2024-10-29T09:50:02.258Z","etag":null,"topics":["django","go","golang","golang-library","pongo2","template","template-engine","template-language","templates"],"latest_commit_sha":null,"homepage":"https://www.schlachter.tech/pongo2","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/flosch.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["flosch"]}},"created_at":"2013-08-23T01:00:08.000Z","updated_at":"2024-10-29T07:37:24.000Z","dependencies_parsed_at":"2023-12-15T10:05:51.192Z","dependency_job_id":"bb802372-7fc5-4aea-bc02-15da28457aa6","html_url":"https://github.com/flosch/pongo2","commit_stats":{"total_commits":491,"total_committers":56,"mean_commits":8.767857142857142,"dds":"0.18329938900203668","last_synced_commit":"c84aecb5fa79a9c0feec284a7bf4f0536c6a6e99"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Fpongo2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Fpongo2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Fpongo2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/flosch%2Fpongo2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/flosch","download_url":"https://codeload.github.com/flosch/pongo2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243271409,"owners_count":20264451,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","go","golang","golang-library","pongo2","template","template-engine","template-language","templates"],"created_at":"2024-07-30T00:01:37.302Z","updated_at":"2025-03-12T18:31:51.689Z","avatar_url":"https://github.com/flosch.png","language":"Go","readme":"# [pongo](https://en.wikipedia.org/wiki/Pongo_%28genus%29)2\n\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/flosch/pongo2)](https://pkg.go.dev/github.com/flosch/pongo2)\n[![Build Status](https://schlachterinf.semaphoreci.com/badges/pongo2/branches/master.svg?style=shields\u0026key=4ecde757-d6dd-4db2-8998-c84f55253d8f)](https://schlachterinf.semaphoreci.com/projects/pongo2)\n[![Run on Repl.it](https://repl.it/badge/github/flosch/pongo2)](https://repl.it/github/flosch/pongo2)\n\npongo2 is a Django-syntax like templating-language ([official website](https://www.schlachter.tech/solutions/pongo2-template-engine/)).\n\nInstall/update using `go get` (no dependencies required by pongo2):\n\n```sh\ngo get -u github.com/flosch/pongo2/v6\n```\n\nPlease use the [issue tracker](https://github.com/flosch/pongo2/issues) if you're encountering any problems with pongo2 or if you need help with implementing tags or filters ([create a ticket!](https://github.com/flosch/pongo2/issues/new)).\n\n:question: [**Looking for a Go developer/consultant?** I'm available for hire. :man_technologist:](mailto:florian@schlachter.tech )\n\n## First impression of a template\n\n```django\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003ctitle\u003eOur admins and users\u003c/title\u003e\n  \u003c/head\u003e\n  {# This is a short example to give you a quick overview of pongo2's syntax. #}\n  {% macro user_details(user, is_admin=false) %}\n  \u003cdiv class=\"user_item\"\u003e\n    \u003c!-- Let's indicate a user's good karma --\u003e\n    \u003ch2 {% if (user.karma\u003e= 40) || (user.karma \u003e calc_avg_karma(userlist)+5) %} class=\"karma-good\"{% endif %}\u003e\n\n      \u003c!-- This will call user.String() automatically if available: --\u003e\n      {{ user }}\n    \u003c/h2\u003e\n\n    \u003c!-- Will print a human-readable time duration like \"3 weeks ago\" --\u003e\n    \u003cp\u003eThis user registered {{ user.register_date|naturaltime }}.\u003c/p\u003e\n\n    \u003c!-- Let's allow the users to write down their biography using markdown;\n             we will only show the first 15 words as a preview --\u003e\n    \u003cp\u003eThe user's biography:\u003c/p\u003e\n    \u003cp\u003e\n      {{ user.biography|markdown|truncatewords_html:15 }}\n      \u003ca href=\"/user/{{ user.id }}/\"\u003eread more\u003c/a\u003e\n    \u003c/p\u003e\n\n    {% if is_admin %}\n    \u003cp\u003eThis user is an admin!\u003c/p\u003e\n    {% endif %}\n  \u003c/div\u003e\n  {% endmacro %}\n\n  \u003cbody\u003e\n    \u003c!-- Make use of the macro defined above to avoid repetitive HTML code\n         since we want to use the same code for admins AND members --\u003e\n\n    \u003ch1\u003eOur admins\u003c/h1\u003e\n    {% for admin in adminlist %} {{ user_details(admin, true) }} {% endfor %}\n\n    \u003ch1\u003eOur members\u003c/h1\u003e\n    {% for user in userlist %} {{ user_details(user) }} {% endfor %}\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Features\n\n- Syntax- and feature-set-compatible with [Django 1.7](https://django.readthedocs.io/en/1.7.x/topics/templates.html)\n- [Advanced C-like expressions](https://github.com/flosch/pongo2/blob/master/template_tests/expressions.tpl).\n- [Complex function calls within expressions](https://github.com/flosch/pongo2/blob/master/template_tests/function_calls_wrapper.tpl).\n- [Easy API to create new filters and tags](http://godoc.org/github.com/flosch/pongo2#RegisterFilter) ([including parsing arguments](http://godoc.org/github.com/flosch/pongo2#Parser))\n- Additional features:\n  - Macros including importing macros from other files (see [template_tests/macro.tpl](https://github.com/flosch/pongo2/blob/master/template_tests/macro.tpl))\n  - [Template sandboxing](https://godoc.org/github.com/flosch/pongo2#TemplateSet) ([directory patterns](http://golang.org/pkg/path/filepath/#Match), banned tags/filters)\n\n## Caveats\n\n### Filters\n\n- **date** / **time**: The `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](http://golang.org/pkg/time/#Time.Format).\n- **stringformat**: `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)`.\n- **escape** / **force_escape**: Unlike Django's behaviour, the `escape`-filter is applied immediately. Therefore there is no need for a `force_escape`-filter yet.\n\n### Tags\n\n- **for**: All the `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`.\n- **now**: takes Go's time format (see **date** and **time**-filter).\n\n### Misc\n\n- **not in-operator**: You can check whether a map/struct/string contains a key/field/substring by using the in-operator (or the negation of it):\n  `{% 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 %}`.\n\n## Add-ons, libraries and helpers\n\n### Official\n\n- [pongo2-addons](https://github.com/flosch/pongo2-addons) - Official additional filters/tags for pongo2 (for example a **markdown**-filter). They are in their own repository because they're relying on 3rd-party-libraries.\n\n### 3rd-party\n\n- [beego-pongo2](https://github.com/oal/beego-pongo2) - A tiny little helper for using Pongo2 with [Beego](https://github.com/astaxie/beego).\n- [beego-pongo2.v2](https://github.com/ipfans/beego-pongo2.v2) - Same as `beego-pongo2`, but for pongo2 v2.\n- [macaron-pongo2](https://github.com/macaron-contrib/pongo2) - pongo2 support for [Macaron](https://github.com/Unknwon/macaron), a modular web framework.\n- [ginpongo2](https://github.com/ngerakines/ginpongo2) - middleware for [gin](github.com/gin-gonic/gin) to use pongo2 templates\n- [Build'n support for Iris' template engine](https://github.com/kataras/iris)\n- [pongo2gin](https://gitlab.com/go-box/pongo2gin) - alternative renderer for [gin](github.com/gin-gonic/gin) to use pongo2 templates\n- [pongo2-trans](https://github.com/digitalcrab/pongo2trans) - `trans`-tag implementation for internationalization\n- [tpongo2](https://github.com/tango-contrib/tpongo2) - pongo2 support for [Tango](https://github.com/lunny/tango), a micro-kernel \u0026 pluggable web framework.\n- [p2cli](https://github.com/wrouesnel/p2cli) - command line templating utility based on pongo2\n- [pongorenderer](https://github.com/siredwin/pongorenderer) - minimal pongo2 renderer for [Echo](https://github.com/labstack/echo) web framework\n- [pongo2gcloud](https://github.com/dieselburner/pongo2gcloud) - Google Cloud Storage loader for pongo2 template files\n\nPlease add your project to this list and send me a pull request when you've developed something nice for pongo2.\n\n## Who's using pongo2\n\n[I'm compiling a list of pongo2 users](https://github.com/flosch/pongo2/issues/241). Add your project or company!\n\n## API-usage examples\n\nPlease see the documentation for a full list of provided API methods.\n\n### A tiny example (template string)\n\n```go\n// Compile the template first (i. e. creating the AST)\ntpl, err := pongo2.FromString(\"Hello {{ name|capfirst }}!\")\nif err != nil {\n    panic(err)\n}\n// Now you can render the template with the given\n// pongo2.Context how often you want to.\nout, err := tpl.Execute(pongo2.Context{\"name\": \"florian\"})\nif err != nil {\n    panic(err)\n}\nfmt.Println(out) // Output: Hello Florian!\n```\n\n## Example server-usage (template file)\n\n```go\npackage main\n\nimport (\n    \"github.com/flosch/pongo2/v6\"\n    \"net/http\"\n)\n\n// Pre-compiling the templates at application startup using the\n// little Must()-helper function (Must() will panic if FromFile()\n// or FromString() will return with an error - that's it).\n// It's faster to pre-compile it anywhere at startup and only\n// execute the template later.\nvar tplExample = pongo2.Must(pongo2.FromFile(\"example.html\"))\n\nfunc examplePage(w http.ResponseWriter, r *http.Request) {\n    // Execute the template per HTTP request\n    err := tplExample.ExecuteWriter(pongo2.Context{\"query\": r.FormValue(\"query\")}, w)\n    if err != nil {\n        http.Error(w, err.Error(), http.StatusInternalServerError)\n    }\n}\n\nfunc main() {\n    http.HandleFunc(\"/\", examplePage)\n    http.ListenAndServe(\":8080\", nil)\n}\n```\n","funding_links":["https://github.com/sponsors/flosch"],"categories":["模板引擎"],"sub_categories":["高级控制台界面","高級控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosch%2FponGo2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fflosch%2FponGo2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fflosch%2FponGo2/lists"}