mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17: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:
29
_examples/view/template_pug_0/main.go
Normal file
29
_examples/view/template_pug_0/main.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
tmpl := iris.Pug("./templates", ".pug")
|
||||
tmpl.Reload(true) // reload templates on each request (development mode)
|
||||
tmpl.AddFunc("greet", func(s string) string { // add your template func here.
|
||||
return "Greetings " + s + "!"
|
||||
})
|
||||
|
||||
app.RegisterView(tmpl)
|
||||
|
||||
app.Get("/", index)
|
||||
|
||||
// http://localhost:8080
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
func index(ctx iris.Context) {
|
||||
ctx.ViewData("pageTitle", "My Index Page")
|
||||
ctx.ViewData("youAreUsingJade", true)
|
||||
// Q: why need extension .pug?
|
||||
// A: Because you can register more than one view engine per Iris application.
|
||||
ctx.View("index.pug")
|
||||
|
||||
}
|
||||
25
_examples/view/template_pug_0/templates/index.pug
Normal file
25
_examples/view/template_pug_0/templates/index.pug
Normal file
@@ -0,0 +1,25 @@
|
||||
mixin withGo
|
||||
| Generating Go html/template output.
|
||||
|
||||
doctype html
|
||||
html(lang="en")
|
||||
head
|
||||
title= .pageTitle
|
||||
script(type='text/javascript').
|
||||
if (foo) {
|
||||
bar(1 + 5)
|
||||
}
|
||||
body
|
||||
h1 Jade - template engine
|
||||
#container.col
|
||||
if .youAreUsingJade
|
||||
p {{ greet "iris user" }} <!-- execute template funcs -->
|
||||
p You are amazing!
|
||||
else
|
||||
p Get on it!
|
||||
p.
|
||||
Jade is #[a(terse)] and simple
|
||||
templating language with a
|
||||
#[strong focus] on performance
|
||||
and powerful features.
|
||||
+ withGo
|
||||
Reference in New Issue
Block a user