mirror of
https://github.com/kataras/iris.git
synced 2026-01-23 11:56:00 +00:00
Full support of the http.FileSystem on all view engines as requested at #1575
Also, the HandleDir accepts both string and http.FileSystem (interface{}) (like the view's fs)
This commit is contained in:
@@ -1,24 +1,20 @@
|
||||
// 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/v12"
|
||||
import (
|
||||
"html/template"
|
||||
|
||||
type Person struct {
|
||||
Name string
|
||||
Age int
|
||||
Emails []string
|
||||
Jobs []*Job
|
||||
}
|
||||
|
||||
type Job struct {
|
||||
Employer string
|
||||
Role string
|
||||
}
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
tmpl := iris.Pug("./templates", ".pug")
|
||||
tmpl.Reload(true) // reload templates on each request (development mode)
|
||||
tmpl.AddFunc("bold", func(s string) (template.HTML, error) { // add your template func here.
|
||||
return template.HTML("<b>" + s + "</b>"), nil
|
||||
})
|
||||
|
||||
app.RegisterView(tmpl)
|
||||
|
||||
app.Get("/", index)
|
||||
@@ -28,15 +24,5 @@ func main() {
|
||||
}
|
||||
|
||||
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)
|
||||
ctx.View("index.pug")
|
||||
}
|
||||
|
||||
2
_examples/view/template_pug_1/templates/footer.pug
Normal file
2
_examples/view/template_pug_1/templates/footer.pug
Normal file
@@ -0,0 +1,2 @@
|
||||
#footer
|
||||
p Copyright (c) foobar
|
||||
4
_examples/view/template_pug_1/templates/header.pug
Normal file
4
_examples/view/template_pug_1/templates/header.pug
Normal file
@@ -0,0 +1,4 @@
|
||||
head
|
||||
title My Site
|
||||
<!-- script(src='/javascripts/jquery.js')
|
||||
script(src='/javascripts/app.js') -->
|
||||
@@ -1,20 +1,7 @@
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
meta(charset="utf-8")
|
||||
title Title
|
||||
body
|
||||
p ads
|
||||
ul
|
||||
li The name is {{.Name}}.
|
||||
li The age is {{.Age}}.
|
||||
|
||||
each _,_ in .Emails
|
||||
div An email is {{.}}
|
||||
|
||||
| {{ with .Jobs }}
|
||||
each _,_ in .
|
||||
div
|
||||
An employer is {{.Employer}}
|
||||
and the role is {{.Role}}
|
||||
| {{ end }}
|
||||
html
|
||||
include header.pug
|
||||
body
|
||||
h1 My Site
|
||||
p {{ bold "Welcome to my super lame site."}}
|
||||
include footer.pug
|
||||
Reference in New Issue
Block a user