mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 20:37:05 +00:00
Update vendor for Pug (Jade) Parser and add Iris + Pug examples in the _examples/view folder, relative to https://github.com/kataras/iris/issues/1003
Former-commit-id: e26a5701e00ec055f3bcf693c1980c7d22147310
This commit is contained in:
42
_examples/view/template_pug_1/main.go
Normal file
42
_examples/view/template_pug_1/main.go
Normal file
@@ -0,0 +1,42 @@
|
||||
// Package main shows an example of pug actions based on https://github.com/Joker/jade/tree/master/example/actions
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
Age int
|
||||
Emails []string
|
||||
Jobs []*Job
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
Employer string
|
||||
Role string
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
tmpl := iris.Pug("./templates", ".pug")
|
||||
app.RegisterView(tmpl)
|
||||
|
||||
app.Get("/", index)
|
||||
|
||||
// http://localhost:8080
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
func index(ctx iris.Context) {
|
||||
job1 := Job{Employer: "Monash B", Role: "Honorary"}
|
||||
job2 := Job{Employer: "Box Hill", Role: "Head of HE"}
|
||||
|
||||
person := Person{
|
||||
Name: "jan",
|
||||
Age: 50,
|
||||
Emails: []string{"jan@newmarch.name", "jan.newmarch@gmail.com"},
|
||||
Jobs: []*Job{&job1, &job2},
|
||||
}
|
||||
|
||||
ctx.View("index.pug", person)
|
||||
}
|
||||
Reference in New Issue
Block a user