{"id":13471708,"url":"https://github.com/hoisie/mustache","last_synced_at":"2025-05-14T13:06:01.307Z","repository":{"id":55450744,"uuid":"453807","full_name":"hoisie/mustache","owner":"hoisie","description":"The mustache template language in Go","archived":false,"fork":false,"pushed_at":"2024-04-28T16:34:44.000Z","size":315,"stargazers_count":1108,"open_issues_count":33,"forks_count":227,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-04-11T06:01:41.903Z","etag":null,"topics":[],"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/hoisie.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":"2009-12-30T21:05:05.000Z","updated_at":"2025-03-22T16:50:55.000Z","dependencies_parsed_at":"2024-01-13T11:12:52.562Z","dependency_job_id":"c5f2c714-1efe-4159-9595-ed665b95d88a","html_url":"https://github.com/hoisie/mustache","commit_stats":{"total_commits":73,"total_committers":10,"mean_commits":7.3,"dds":0.452054794520548,"last_synced_commit":"6375acf62c69d9d3ad20fd0599d82ca94ea12284"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoisie%2Fmustache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoisie%2Fmustache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoisie%2Fmustache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoisie%2Fmustache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoisie","download_url":"https://codeload.github.com/hoisie/mustache/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149947,"owners_count":22022851,"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":[],"created_at":"2024-07-31T16:00:48.501Z","updated_at":"2025-05-14T13:06:01.280Z","avatar_url":"https://github.com/hoisie.png","language":"Go","funding_links":[],"categories":["开源类库","Go","Open source library","\u003cspan id=\"模板引擎-template-engines\"\u003e模板引擎 Template Engines\u003c/span\u003e","Template Engines","模板引擎","模板引擎`模版渲染和模版生成处理库`","Relational Databases","\u003ca name=\"Go\"\u003e\u003c/a\u003eGo"],"sub_categories":["模板引擎","Template Engine","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","Advanced Console UIs","高級控制台界面","HTTP Clients","Middlewares","查询语","高级控制台界面","交流"],"readme":"## Overview\n\nmustache.go is an implementation of the mustache template language in Go. It is better suited for website templates than Go's native pkg/template. mustache.go is fast -- it parses templates efficiently and stores them in a tree-like structure which allows for fast execution. \n\n## Documentation\n\nFor more information about mustache, check out the [mustache project page](http://github.com/defunkt/mustache) or the [mustache manual](http://mustache.github.com/mustache.5.html).\n\nAlso check out some [example mustache files](http://github.com/defunkt/mustache/tree/master/examples/)\n\n## Installation\nTo install mustache.go, simply run `go get github.com/hoisie/mustache`. To use it in a program, use `import \"github.com/hoisie/mustache\"`\n\n## Usage\nThere are four main methods in this package:\n\n```go\nfunc Render(data string, context ...interface{}) string\n\nfunc RenderFile(filename string, context ...interface{}) string\n\nfunc ParseString(data string) (*Template, os.Error)\n\nfunc ParseFile(filename string) (*Template, os.Error)\n```\n\nThere are also two additional methods for using layouts (explained below).\n\nThe Render method takes a string and a data source, which is generally a map or struct, and returns the output string. If the template file contains an error, the return value is a description of the error. There's a similar method, RenderFile, which takes a filename as an argument and uses that for the template contents. \n\n```go\ndata := mustache.Render(\"hello {{c}}\", map[string]string{\"c\":\"world\"})\nprintln(data)\n```\n\nIf you're planning to render the same template multiple times, you do it efficiently by compiling the template first:\n\n```go\ntmpl,_ := mustache.ParseString(\"hello {{c}}\")\nvar buf bytes.Buffer;\nfor i := 0; i \u003c 10; i++ {\n    tmpl.Render (map[string]string { \"c\":\"world\"}, \u0026buf)  \n}\n```\n\nFor more example usage, please see `mustache_test.go`\n\n## Escaping\n\nmustache.go follows the official mustache HTML escaping rules. That is, if you enclose a variable with two curly brackets, `{{var}}`, the contents are HTML-escaped. For instance, strings like `5 \u003e 2` are converted to `5 \u0026gt; 2`. To use raw characters, use three curly brackets `{{{var}}}`.\n\n## Layouts\n\nIt is a common pattern to include a template file as a \"wrapper\" for other templates. The wrapper may include a header and a footer, for instance. Mustache.go supports this pattern with the following two methods:\n\n```go\nfunc RenderInLayout(data string, layout string, context ...interface{}) string\n\nfunc RenderFileInLayout(filename string, layoutFile string, context ...interface{}) string\n```\n    \nThe layout file must have a variable called `{{content}}`. For example, given the following files:\n\nlayout.html.mustache:\n\n```html\n\u003chtml\u003e\n\u003chead\u003e\u003ctitle\u003eHi\u003c/title\u003e\u003c/head\u003e\n\u003cbody\u003e\n{{{content}}}\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\ntemplate.html.mustache:\n\n```html\n\u003ch1\u003e Hello World! \u003c/h1\u003e\n```\n\nA call to `RenderFileInLayout(\"template.html.mustache\", \"layout.html.mustache\", nil)` will produce:\n\n```html\n\u003chtml\u003e\n\u003chead\u003e\u003ctitle\u003eHi\u003c/title\u003e\u003c/head\u003e\n\u003cbody\u003e\n\u003ch1\u003e Hello World! \u003c/h1\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## A note about method receivers\n\nMustache.go supports calling methods on objects, but you have to be aware of Go's limitations. For example, lets's say you have the following type:\n\n```go\ntype Person struct {\n    FirstName string\n    LastName string    \n}\n\nfunc (p *Person) Name1() string {\n    return p.FirstName + \" \" + p.LastName\n}\n\nfunc (p Person) Name2() string {\n    return p.FirstName + \" \" + p.LastName\n}\n```\n\nWhile they appear to be identical methods, `Name1` has a pointer receiver, and `Name2` has a value receiver. Objects of type `Person`(non-pointer) can only access `Name2`, while objects of type `*Person`(person) can access both. This is by design in the Go language.\n\nSo if you write the following:\n\n```go\nmustache.Render(\"{{Name1}}\", Person{\"John\", \"Smith\"})\n```\n\nIt'll be blank. You either have to use `\u0026Person{\"John\", \"Smith\"}`, or call `Name2`\n\n## Supported features\n\n* Variables\n* Comments\n* Change delimiter\n* Sections (boolean, enumerable, and inverted)\n* Partials\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoisie%2Fmustache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoisie%2Fmustache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoisie%2Fmustache/lists"}