mirror of
https://github.com/kataras/iris.git
synced 2026-01-22 11:25:59 +00:00
minor: examples
This commit is contained in:
34
_examples/view/template_handlebars_0/main.go
Normal file
34
_examples/view/template_handlebars_0/main.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
// Init the handlebars engine
|
||||
engine := iris.Handlebars("./templates", ".html").Reload(true)
|
||||
// Register a helper.
|
||||
engine.AddFunc("fullName", func(person map[string]string) string {
|
||||
return person["firstName"] + " " + person["lastName"]
|
||||
})
|
||||
|
||||
app.RegisterView(engine)
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
viewData := iris.Map{
|
||||
"author": map[string]string{"firstName": "Jean", "lastName": "Valjean"},
|
||||
"body": "Life is difficult",
|
||||
"comments": []iris.Map{{
|
||||
"author": map[string]string{"firstName": "Marcel", "lastName": "Beliveau"},
|
||||
"body": "LOL!",
|
||||
}},
|
||||
}
|
||||
|
||||
ctx.View("example.html", viewData)
|
||||
})
|
||||
|
||||
// Read more about its syntax at:
|
||||
// https://github.com/aymerick/raymond and
|
||||
// https://handlebarsjs.com/guide
|
||||
app.Listen(":8080")
|
||||
}
|
||||
27
_examples/view/template_handlebars_0/templates/example.html
Normal file
27
_examples/view/template_handlebars_0/templates/example.html
Normal file
@@ -0,0 +1,27 @@
|
||||
<div class="post">
|
||||
<h1>By {{fullName author}}</h1>
|
||||
<div class="body">{{body}}</div>
|
||||
|
||||
<h1>Comments</h1>
|
||||
|
||||
{{#each comments}}
|
||||
<h2>By {{fullName author}}</h2>
|
||||
<div class="body">{{body}}</div>
|
||||
{{/each}}
|
||||
|
||||
|
||||
<!-- <h1>Struct example</h1>
|
||||
{{#with myStruct}}
|
||||
{{ this }}
|
||||
OR
|
||||
{{ FieldMame }}
|
||||
{{/with}} -->
|
||||
|
||||
<hr />
|
||||
|
||||
<strong>Read more at: <a href="https://github.com/aymerick/raymond" target="_new">
|
||||
https://github.com/aymerick/raymond</a> and <a href="https://handlebarsjs.com/guide" target="_new">
|
||||
https://handlebarsjs.com/guide
|
||||
</a>
|
||||
</strong>
|
||||
</div>
|
||||
Reference in New Issue
Block a user