{"id":13413851,"url":"https://github.com/valyala/quicktemplate","last_synced_at":"2025-05-13T18:07:28.815Z","repository":{"id":40633384,"uuid":"53277717","full_name":"valyala/quicktemplate","owner":"valyala","description":"Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template","archived":false,"fork":false,"pushed_at":"2024-07-21T02:16:20.000Z","size":1624,"stargazers_count":3199,"open_issues_count":39,"forks_count":150,"subscribers_count":66,"default_branch":"master","last_synced_at":"2025-04-25T15:48:21.558Z","etag":null,"topics":["fast","golang","template-engine"],"latest_commit_sha":null,"homepage":"","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/valyala.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-03-06T21:42:01.000Z","updated_at":"2025-04-24T23:26:11.000Z","dependencies_parsed_at":"2024-09-24T22:41:57.782Z","dependency_job_id":"16151c9a-278f-4140-9b78-62092cd5d930","html_url":"https://github.com/valyala/quicktemplate","commit_stats":{"total_commits":261,"total_committers":19,"mean_commits":"13.736842105263158","dds":0.09195402298850575,"last_synced_commit":"dad80a9c2cc0c2a5abfe1bf13935a2a19f313e63"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Fquicktemplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Fquicktemplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Fquicktemplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/valyala%2Fquicktemplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/valyala","download_url":"https://codeload.github.com/valyala/quicktemplate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254000848,"owners_count":21997441,"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":["fast","golang","template-engine"],"created_at":"2024-07-30T20:01:51.171Z","updated_at":"2025-05-13T18:07:28.790Z","avatar_url":"https://github.com/valyala.png","language":"Go","readme":"[![Build Status](https://travis-ci.org/valyala/quicktemplate.svg)](https://travis-ci.org/valyala/quicktemplate)\n[![GoDoc](https://godoc.org/github.com/valyala/quicktemplate?status.svg)](http://godoc.org/github.com/valyala/quicktemplate)\n[![Go Report Card](https://goreportcard.com/badge/github.com/valyala/quicktemplate)](https://goreportcard.com/report/github.com/valyala/quicktemplate)\n\n# quicktemplate\n\nA fast, powerful, yet easy to use template engine for Go.\nInspired by the [Mako templates](http://www.makotemplates.org/) philosophy.\n\n# Features\n\n  * [Extremely fast](#performance-comparison-with-htmltemplate).\n    Templates are converted into Go code and then compiled.\n  * Quicktemplate syntax is very close to Go - there is no need to learn\n    yet another template language before starting to use quicktemplate.\n  * Almost all bugs are caught during template compilation, so production\n    suffers less from template-related bugs.\n  * Easy to use. See [quickstart](#quick-start) and [examples](https://github.com/valyala/quicktemplate/tree/master/examples)\n    for details.\n  * Powerful. Arbitrary Go code may be embedded into and mixed with templates.\n    Be careful with this power - do not query the database and/or external resources from\n    templates unless you miss the PHP way in Go :) This power is mostly for\n    arbitrary data transformations.\n  * Easy to use template inheritance powered by [Go interfaces](https://golang.org/doc/effective_go.html#interfaces).\n    See [this example](https://github.com/valyala/quicktemplate/tree/master/examples/basicserver) for details.\n  * Templates are compiled into a single binary, so there is no need to copy\n    template files to the server.\n\n# Drawbacks\n\n  * Templates cannot be updated on the fly on the server, since they\n    are compiled into a single binary.\n    Take a look at [fasttemplate](https://github.com/valyala/fasttemplate)\n    if you need a fast template engine for simple dynamically updated templates.\n    [There are ways](https://www.reddit.com/r/golang/comments/f290ja/hot_reloading_with_quicktemplates_sqlc_and/) to dynamically update the templates during development.\n\n# Performance comparison with html/template\n\nQuicktemplate is more than 20x faster than [html/template](https://golang.org/pkg/html/template/).\nThe following simple template is used in the benchmark:\n\n  * [html/template version](https://github.com/valyala/quicktemplate/blob/master/testdata/templates/bench.tpl)\n  * [quicktemplate version](https://github.com/valyala/quicktemplate/blob/master/testdata/templates/bench.qtpl)\n\nBenchmark results:\n\n```\n$ go test -bench='Benchmark(Quick|HTML)Template' -benchmem github.com/valyala/quicktemplate/tests\nBenchmarkQuickTemplate1-4                 \t10000000\t       120 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQuickTemplate10-4                \t 3000000\t       441 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkQuickTemplate100-4               \t  300000\t      3945 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkHTMLTemplate1-4                  \t  500000\t      2501 ns/op\t     752 B/op\t      23 allocs/op\nBenchmarkHTMLTemplate10-4                 \t  100000\t     12442 ns/op\t    3521 B/op\t     117 allocs/op\nBenchmarkHTMLTemplate100-4                \t   10000\t    123392 ns/op\t   34498 B/op\t    1152 allocs/op\n```\n\n[goTemplateBenchmark](https://github.com/SlinSo/goTemplateBenchmark) compares QuickTemplate with numerous Go templating packages. QuickTemplate performs favorably.\n\n# Security\n\n  * All template placeholders are HTML-escaped by default.\n  * Template placeholders for JSON strings prevent from `\u003c/script\u003e`-based\n    XSS attacks:\n\n  ```qtpl\n  {% func FailedXSS() %}\n  \u003cscript\u003e\n      var s = {%q= \"\u003c/script\u003e\u003cscript\u003ealert('you pwned!')\" %};\n  \u003c/script\u003e\n  {% endfunc %}\n  ```\n\n# Examples\n\nSee [examples](https://github.com/valyala/quicktemplate/tree/master/examples).\n\n# Quick start\n\nFirst of all, install the `quicktemplate` package\nand [quicktemplate compiler](https://github.com/valyala/quicktemplate/tree/master/qtc) (`qtc`):\n\n```\ngo get -u github.com/valyala/quicktemplate\ngo get -u github.com/valyala/quicktemplate/qtc\n```\n\nIf you using `go generate`, you just need put following into your `main.go`\n\nImportant: please specify your own folder (-dir) to generate template file\n\n```\n//go:generate go get -u github.com/valyala/quicktemplate/qtc\n//go:generate qtc -dir=app/views  \n```\n\nLet's start with a minimal template example:\n\n```qtpl\nAll text outside function templates is treated as comments,\ni.e. it is just ignored by quicktemplate compiler (`qtc`). It is for humans.\n\nHello is a simple template function.\n{% func Hello(name string) %}\n\tHello, {%s name %}!\n{% endfunc %}\n```\n\nSave this file into a `templates` folder under the name `hello.qtpl`\nand run `qtc` inside this folder.\n\nIf everything went OK, `hello.qtpl.go` file should appear in the `templates` folder.\nThis file contains Go code for `hello.qtpl`. Let's use it!\n\nCreate a file main.go outside `templates` folder and put the following\ncode there:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"./templates\"\n)\n\nfunc main() {\n\tfmt.Printf(\"%s\\n\", templates.Hello(\"Foo\"))\n\tfmt.Printf(\"%s\\n\", templates.Hello(\"Bar\"))\n}\n```\n\nThen issue `go run`. If everything went OK, you'll see something like this:\n\n```\n\n\tHello, Foo!\n\n\n\tHello, Bar!\n\n```\n\nLet's create more a complex template which calls other template functions,\ncontains loops, conditions, breaks, continues and returns.\nPut the following template into `templates/greetings.qtpl`:\n\n```qtpl\n\nGreetings greets up to 42 names.\nIt also greets John differently comparing to others.\n{% func Greetings(names []string) %}\n\t{% if len(names) == 0 %}\n\t\tNobody to greet :(\n\t\t{% return %}\n\t{% endif %}\n\n\t{% for i, name := range names %}\n\t\t{% if i == 42 %}\n\t\t\tI'm tired to greet so many people...\n\t\t\t{% break %}\n\t\t{% elseif name == \"John\" %}\n\t\t\t{%= sayHi(\"Mr. \" + name) %}\n\t\t\t{% continue %}\n\t\t{% else %}\n\t\t\t{%= Hello(name) %}\n\t\t{% endif %}\n\t{% endfor %}\n{% endfunc %}\n\nsayHi is unexported, since it starts with lowercase letter.\n{% func sayHi(name string) %}\n\tHi, {%s name %}\n{% endfunc %}\n\nNote that every template file may contain an arbitrary number\nof template functions. For instance, this file contains Greetings and sayHi\nfunctions.\n```\n\nRun `qtc` inside `templates` folder. Now the folder should contain\ntwo files with Go code: `hello.qtpl.go` and `greetings.qtpl.go`. These files\nform a single `templates` Go package. Template functions and other template\nstuff is shared between template files located in the same folder.\nSo `Hello` template function may be used inside `greetings.qtpl` while\nit is defined in `hello.qtpl`.\nMoreover, the folder may contain ordinary Go files, so its contents may\nbe used inside templates and vice versa.\nThe package name inside template files may be overriden\nwith `{% package packageName %}`.\n\nNow put the following code into `main.go`:\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\n\t\"./templates\"\n)\n\nfunc main() {\n\tnames := []string{\"Kate\", \"Go\", \"John\", \"Brad\"}\n\n\t// qtc creates Write* function for each template function.\n\t// Such functions accept io.Writer as first parameter:\n\tvar buf bytes.Buffer\n\ttemplates.WriteGreetings(\u0026buf, names)\n\n\tfmt.Printf(\"buf=\\n%s\", buf.Bytes())\n}\n```\n\nCareful readers may notice different output tags were used in these\ntemplates: `{%s name %}` and `{%= Hello(name) %}`. What's the difference?\nThe `{%s x %}` is used for printing HTML-safe strings, while `{%= F() %}`\nis used for embedding template function calls. Quicktemplate supports also\nother output tags:\n\n  * `{%d int %}` and `{%dl int64 %}` `{%dul uint64 %}` for integers.\n  * `{%f float %}` for float64.\n    Floating point precision may be set via `{%f.precision float %}`.\n    For example, `{%f.2 1.2345 %}` outputs `1.23`.\n  * `{%z bytes %}` for byte slices.\n  * `{%q str %}` and `{%qz bytes %}` for JSON-compatible quoted strings.\n  * `{%j str %}` and `{%jz bytes %}` for embedding str into a JSON string. Unlike `{%q str %}`,\n    it doesn't quote the string.\n  * `{%u str %}` and `{%uz bytes %}` for [URL encoding](https://en.wikipedia.org/wiki/Percent-encoding)\n    the given str.\n  * `{%v anything %}` is equivalent to `%v` in [printf-like functions](https://golang.org/pkg/fmt/).\n\nAll the output tags except `{%= F() %}` produce HTML-safe output, i.e. they\nescape `\u003c` to `\u0026lt;`, `\u003e` to `\u0026gt;`, etc. If you don't want HTML-safe output,\nthen just put `=` after the tag. For example: `{%s= \"\u003ch1\u003eThis h1 won't be escaped\u003c/h1\u003e\" %}`.\n\nAs you may notice `{%= F() %}` and `{%s= F() %}` produce the same output for `{% func F() %}`.\nBut the first one is optimized for speed - it avoids memory allocations and copies.\nIt is therefore recommended to stick to it when embedding template function calls.\n\nAdditionally, the following extensions are supported for `{%= F() %}`:\n\n  * `{%=h F() %}` produces html-escaped output.\n  * `{%=u F() %}` produces [URL-encoded](https://en.wikipedia.org/wiki/Percent-encoding) output.\n  * `{%=q F() %}` produces quoted json string.\n  * `{%=j F() %}` produces json string without quotes.\n  * `{%=uh F() %}` produces html-safe URL-encoded output.\n  * `{%=qh F() %}` produces html-safe quoted json string.\n  * `{%=jh F() %}` produces html-safe json string without quotes.\n\nAll output tags except `{%= F() %}` family may contain arbitrary valid\nGo expressions instead of just an identifier. For example:\n\n```qtpl\nImport fmt for fmt.Sprintf()\n{% import \"fmt\" %}\n\nFmtFunc uses fmt.Sprintf() inside output tag\n{% func FmtFunc(s string) %}\n\t{%s fmt.Sprintf(\"FmtFunc accepted %q string\", s) %}\n{% endfunc %}\n```\n\nThere are other useful tags supported by quicktemplate:\n\n  * `{% comment %}`\n\n    ```qtpl\n    {% comment %}\n        This is a comment. It won't trap into the output.\n        It may contain {% arbitrary tags %}. They are just ignored.\n    {% endcomment %}\n    ```\n\n  * `{% plain %}`\n\n    ```qtpl\n    {% plain %}\n        Tags will {% trap into %} the output {% unmodified %}.\n        Plain block may contain invalid and {% incomplete tags.\n    {% endplain %}\n    ```\n\n  * `{% collapsespace %}`\n\n    ```qtpl\n    {% collapsespace %}\n        \u003cdiv\u003e\n            \u003cdiv\u003espace between lines\u003c/div\u003e\n               and {%s \"tags\" %}\n             \u003cdiv\u003eis collapsed into a single space\n             unless{% newline %}or{% space %}is used\u003c/div\u003e\n        \u003c/div\u003e\n    {% endcollapsespace %}\n    ```\n\n    Is converted into:\n\n    ```\n    \u003cdiv\u003e \u003cdiv\u003espace between lines\u003c/div\u003e and tags \u003cdiv\u003eis collapsed into a single space unless\n    or is used\u003c/div\u003e \u003c/div\u003e\n    ```\n\n  * `{% stripspace %}`\n\n    ```qtpl\n    {% stripspace %}\n         \u003cdiv\u003e\n             \u003cdiv\u003espace between lines\u003c/div\u003e\n                and {%s \" tags\" %}\n             \u003cdiv\u003eis removed unless{% newline %}or{% space %}is used\u003c/div\u003e\n         \u003c/div\u003e\n    {% endstripspace %}\n    ```\n\n    Is converted into:\n\n    ```\n    \u003cdiv\u003e\u003cdiv\u003espace between lines\u003c/div\u003eand tags\u003cdiv\u003eis removed unless\n    or is used\u003c/div\u003e\u003c/div\u003e\n    ```\n\n  * It is possible removing whitespace before and after the tag by adding `-` after `{%` or prepending `%}` with `-`. For example:\n\n    ```qtpl\n    var sum int\n    {%- for i := 1; i \u003c= 3; i++ -%}\n    sum += {%d i %}\n    {%- endfor -%}\n    return sum\n    ```\n\n    Is converted into:\n    ```\n    var sum int\n    sum += 1\n    sum += 2\n    sum += 3\n    return sum\n    ```\n\n  * `{% switch %}`, `{% case %}` and `{% default %}`:\n\n\n    ```qtpl\n    1 + 1 =\n    {% switch 1+1 %}\n    {% case 2 %}\n\t2?\n    {% case 42 %}\n\t42!\n    {% default %}\n        I don't know :(\n    {% endswitch %}\n    ```\n\n  * `{% code %}`:\n\n    ```qtpl\n    {% code\n    // arbitrary Go code may be embedded here!\n    type FooArg struct {\n        Name string\n        Age int\n    }\n    %}\n    ```\n\n  * `{% package %}`:\n\n    ```qtpl\n    Override default package name with the custom name\n    {% package customPackageName %}\n    ```\n\n  * `{% import %}`:\n\n    ```qtpl\n    Import external packages.\n    {% import \"foo/bar\" %}\n    {% import (\n        \"foo\"\n        bar \"baz/baa\"\n    ) %}\n    ```\n\n  * `{% cat \"/path/to/file\" %}`:\n\n    ```qtpl\n    Cat emits the given file contents as a plaintext:\n    {% func passwords() %}\n        /etc/passwd contents:\n        {% cat \"/etc/passwd\" %}\n    {% endfunc %}\n    ```\n\n  * `{% interface %}`:\n\n    ```qtpl\n    Interfaces allow powerful templates' inheritance\n    {%\n    interface Page {\n        Title()\n        Body(s string, n int)\n        Footer()\n    }\n    %}\n\n    PrintPage prints Page\n    {% func PrintPage(p Page) %}\n        \u003chtml\u003e\n            \u003chead\u003e\u003ctitle\u003e{%= p.Title() %}\u003c/title\u003e\u003c/head\u003e\n            \u003cbody\u003e\n                \u003cdiv\u003e{%= p.Body(\"foo\", 42) %}\u003c/div\u003e\n                \u003cdiv\u003e{%= p.Footer() %}\u003c/div\u003e\n            \u003c/body\u003e\n        \u003c/html\u003e\n    {% endfunc %}\n\n    Base page implementation\n    {% code\n    type BasePage struct {\n        TitleStr string\n        FooterStr string\n    }\n    %}\n    {% func (bp *BasePage) Title() %}{%s bp.TitleStr %}{% endfunc %}\n    {% func (bp *BasePage) Body(s string, n int) %}\n        \u003cb\u003es={%q s %}, n={%d n %}\u003c/b\u003e\n    {% endfunc %}\n    {% func (bp *BasePage) Footer() %}{%s bp.FooterStr %}{% endfunc %}\n\n    Main page implementation\n    {% code\n    type MainPage struct {\n        // inherit from BasePage\n        BasePage\n\n        // real body for main page\n        BodyStr string\n    }\n    %}\n\n    Override only Body\n    Title and Footer are used from BasePage.\n    {% func (mp *MainPage) Body(s string, n int) %}\n        \u003cdiv\u003e\n            main body: {%s mp.BodyStr %}\n        \u003c/div\u003e\n        \u003cdiv\u003e\n            base body: {%= mp.BasePage.Body(s, n) %}\n        \u003c/div\u003e\n    {% endfunc %}\n    ```\n\n    See [basicserver example](https://github.com/valyala/quicktemplate/tree/master/examples/basicserver)\n    for more details.\n\n# Performance optimization tips\n\n  * Prefer calling `WriteFoo` instead of `Foo` when generating template output\n    for `{% func Foo() %}`. This avoids unnesessary memory allocation and a copy\n    for a `string` returned from `Foo()`.\n\n  * Prefer `{%= Foo() %}` instead of `{%s= Foo() %}` when embedding\n    a function template `{% func Foo() %}`. Though both approaches generate\n    identical output, the first approach is optimized for speed.\n\n  * Prefer using existing output tags instead of passing `fmt.Sprintf`\n    to `{%s %}`. For instance, use `{%d num %}` instead\n    of `{%s fmt.Sprintf(\"%d\", num) %}`, because the first approach is optimized\n    for speed.\n\n  * Prefer using specific output tags instead of generic output tag\n    `{%v %}`. For example, use `{%s str %}` instead of `{%v str %}`, since\n    specific output tags are optimized for speed.\n\n  * Prefer creating custom function templates instead of composing complex\n    strings by hands before passing them to `{%s %}`.\n    For instance, the first approach is slower than the second one:\n\n    ```qtpl\n    {% func Foo(n int) %}\n        {% code\n        // construct complex string\n        complexStr := \"\"\n        for i := 0; i \u003c n; i++ {\n            complexStr += fmt.Sprintf(\"num %d,\", i)\n        }\n        %}\n        complex string = {%s= complexStr %}\n    {% endfunc %}\n    ```\n\n    ```qtpl\n    {% func Foo(n int) %}\n        complex string = {%= complexStr(n) %}\n    {% endfunc %}\n\n    // Wrap complexStr func into stripspace for stripping unnesessary space\n    // between tags and lines.\n    {% stripspace %}\n    {% func complexStr(n int) %}\n        {% for i := 0; i \u003c n; i++ %}\n            num{% space %}{%d i %}{% newline %}\n        {% endfor %}\n    {% endfunc %}\n    {% endstripspace %}\n    ```\n\n  * Make sure that the `io.Writer` passed to `Write*` functions\n    is [buffered](https://golang.org/pkg/bufio/#Writer).\n    This will minimize the number of `write`\n    [syscalls](https://en.wikipedia.org/wiki/System_call),\n    which may be quite expensive.\n\n    Note: There is no need to wrap [fasthttp.RequestCtx](https://godoc.org/github.com/valyala/fasthttp#RequestCtx)\n    into [bufio.Writer](https://golang.org/pkg/bufio/#Writer), since it is already buffered.\n\n  * [Profile](http://blog.golang.org/profiling-go-programs) your programs\n    for memory allocations and fix the most demanding functions based on\n    the output of `go tool pprof --alloc_objects`.\n\n# Use cases\n\nWhile the main quicktemplate purpose is generating HTML, it may be used\nfor generating other data too. For example, JSON and XML marshalling may\nbe easily implemented with quicktemplate:\n\n```qtpl\n{% code\ntype MarshalRow struct {\n\tMsg string\n\tN int\n}\n\ntype MarshalData struct {\n\tFoo int\n\tBar string\n\tRows []MarshalRow\n}\n%}\n\n// JSON marshaling\n{% stripspace %}\n{% func (d *MarshalData) JSON() %}\n{\n\t\"Foo\": {%d d.Foo %},\n\t\"Bar\": {%q= d.Bar %},\n\t\"Rows\":[\n\t\t{% for i, r := range d.Rows %}\n\t\t\t{\n\t\t\t\t\"Msg\": {%q= r.Msg %},\n\t\t\t\t\"N\": {%d r.N %}\n\t\t\t}\n\t\t\t{% if i + 1 \u003c len(d.Rows) %},{% endif %}\n\t\t{% endfor %}\n\t]\n}\n{% endfunc %}\n{% endstripspace %}\n\n// XML marshalling\n{% stripspace %}\n{% func (d *MarshalData) XML() %}\n\u003cMarshalData\u003e\n\t\u003cFoo\u003e{%d d.Foo %}\u003c/Foo\u003e\n\t\u003cBar\u003e{%s d.Bar %}\u003c/Bar\u003e\n\t\u003cRows\u003e\n\t{% for _, r := range d.Rows %}\n\t\t\u003cRow\u003e\n\t\t\t\u003cMsg\u003e{%s r.Msg %}\u003c/Msg\u003e\n\t\t\t\u003cN\u003e{%d r.N %}\u003c/N\u003e\n\t\t\u003c/Row\u003e\n\t{% endfor %}\n\t\u003c/Rows\u003e\n\u003c/MarshalData\u003e\n{% endfunc %}\n{% endstripspace %}\n```\n\nUsually, marshalling built with quicktemplate works faster than the marshalling\nimplemented via standard [encoding/json](https://golang.org/pkg/encoding/json/)\nand [encoding/xml](https://golang.org/pkg/encoding/xml/).\nSee the corresponding benchmark results:\n\n```\ngo test -bench=Marshal -benchmem github.com/valyala/quicktemplate/tests\nBenchmarkMarshalJSONStd1-4                \t 3000000\t       480 ns/op\t       8 B/op\t       1 allocs/op\nBenchmarkMarshalJSONStd10-4               \t 1000000\t      1842 ns/op\t       8 B/op\t       1 allocs/op\nBenchmarkMarshalJSONStd100-4              \t  100000\t     15820 ns/op\t       8 B/op\t       1 allocs/op\nBenchmarkMarshalJSONStd1000-4             \t   10000\t    159327 ns/op\t      59 B/op\t       1 allocs/op\nBenchmarkMarshalJSONQuickTemplate1-4      \t10000000\t       162 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkMarshalJSONQuickTemplate10-4     \t 2000000\t       748 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkMarshalJSONQuickTemplate100-4    \t  200000\t      6572 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkMarshalJSONQuickTemplate1000-4   \t   20000\t     66784 ns/op\t      29 B/op\t       0 allocs/op\nBenchmarkMarshalXMLStd1-4                 \t 1000000\t      1652 ns/op\t       2 B/op\t       2 allocs/op\nBenchmarkMarshalXMLStd10-4                \t  200000\t      7533 ns/op\t      11 B/op\t      11 allocs/op\nBenchmarkMarshalXMLStd100-4               \t   20000\t     65763 ns/op\t     195 B/op\t     101 allocs/op\nBenchmarkMarshalXMLStd1000-4              \t    2000\t    663373 ns/op\t    3522 B/op\t    1002 allocs/op\nBenchmarkMarshalXMLQuickTemplate1-4       \t10000000\t       145 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkMarshalXMLQuickTemplate10-4      \t 3000000\t       597 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkMarshalXMLQuickTemplate100-4     \t  300000\t      5833 ns/op\t       0 B/op\t       0 allocs/op\nBenchmarkMarshalXMLQuickTemplate1000-4    \t   30000\t     53000 ns/op\t      32 B/op\t       0 allocs/op\n```\n\n# FAQ\n\n  * *Why is the quicktemplate syntax incompatible with [html/template](https://golang.org/pkg/html/template/)?*\n\n    Because `html/template` syntax isn't expressive enough for `quicktemplate`.\n\n  * *What's the difference between quicktemplate and [ego](https://github.com/benbjohnson/ego)?*\n\n    `Ego` is similar to `quicktemplate` in the sense it converts templates into Go code.\n    But it misses the following stuff, which makes `quicktemplate` so powerful\n    and easy to use:\n\n      * Defining multiple function templates in a single template file.\n      * Embedding function templates inside other function templates.\n      * Template interfaces, inheritance and overriding.\n        See [this example](https://github.com/valyala/quicktemplate/tree/master/examples/basicserver)\n        for details.\n      * Top-level comments outside function templates.\n      * Template packages.\n      * Combining arbitrary Go files with template files in template packages.\n      * Performance optimizations.\n\n  * *What's the difference between quicktemplate and [gorazor](https://github.com/sipin/gorazor)?*\n\n    `Gorazor` is similar to `quicktemplate` in the sense it converts templates into Go code.\n    But it misses the following useful features:\n\n      * Clear syntax instead of hard-to-understand magic stuff related\n        to template arguments, template inheritance and embedding function\n        templates into other templates.\n\n* *Is there a syntax highlighting for qtpl files?*\n\n  Yes - see [this issue](https://github.com/valyala/quicktemplate/issues/19) for details.\n  If you are using JetBrains products (syntax highlighting and autocomplete):\n    * cd [JetBrains settings directory](https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs)\n    * mkdir -p filetypes \u0026\u0026 cd filetypes\n    * curl https://raw.githubusercontent.com/valyala/quicktemplate/master/QuickTemplate.xml \u003e\u003e QuickTemplate.xml\n    * Restart your IDE\n\n* *I didn't find an answer for my question here.*\n\n  Try exploring [these questions](https://github.com/valyala/quicktemplate/issues?q=label%3Aquestion).\n","funding_links":[],"categories":["Misc","开源类库","Template Engines","HTML template engines","Open source library","Go","golang","模板引擎","\u003cspan id=\"模板引擎-template-engines\"\u003e模板引擎 Template Engines\u003c/span\u003e","模板引擎`模版渲染和模版生成处理库`","Relational Databases"],"sub_categories":["模板引擎","HTTP Clients","Template Engine","Advanced Console UIs","查询语","Other Software","高級控制台界面","交互工具","HTTP客户端","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalyala%2Fquicktemplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvalyala%2Fquicktemplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvalyala%2Fquicktemplate/lists"}