-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a 'ParseTemplate' method on view engines to manually parse and ad…
…d a template from a text examples at: https://github.com/kataras/iris/tree/master/_examples/view/parse-template relative to: #1617
- Loading branch information
Showing
13 changed files
with
303 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package main | ||
|
||
import "github.com/kataras/iris/v12" | ||
|
||
func main() { | ||
e := iris.Amber(nil, ".amber") // You can still use a file system though. | ||
e.AddFunc("greet", func(name string) string { | ||
return "Hello, " + name + "!" | ||
}) | ||
err := e.ParseTemplate("program.amber", []byte(`h1 #{ greet(Name) }`)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
app := iris.New() | ||
app.RegisterView(e) | ||
app.Get("/", index) | ||
|
||
app.Listen(":8080") | ||
} | ||
|
||
func index(ctx iris.Context) { | ||
ctx.View("program.amber", iris.Map{ | ||
"Name": "Gerasimos", | ||
// Or per template: | ||
// "greet": func(....) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package main | ||
|
||
import "github.com/kataras/iris/v12" | ||
|
||
func main() { | ||
e := iris.Django(nil, ".html") // You can still use a file system though. | ||
e.AddFunc("greet", func(name string) string { | ||
return "Hello, " + name + "!" | ||
}) | ||
err := e.ParseTemplate("program.html", []byte(`<h1>{{greet(Name)}}</h1>`)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
app := iris.New() | ||
app.RegisterView(e) | ||
app.Get("/", index) | ||
|
||
app.Listen(":8080") | ||
} | ||
|
||
func index(ctx iris.Context) { | ||
ctx.View("program.html", iris.Map{ | ||
"Name": "Gerasimos", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import "github.com/kataras/iris/v12" | ||
|
||
func main() { | ||
e := iris.Handlebars(nil, ".html") // You can still use a file system though. | ||
e.ParseTemplate("program.html", `<h1>{{greet Name}}</h1>`, iris.Map{ | ||
"greet": func(name string) string { | ||
return "Hello, " + name + "!" | ||
}, | ||
}) | ||
|
||
app := iris.New() | ||
app.RegisterView(e) | ||
app.Get("/", index) | ||
|
||
app.Listen(":8080") | ||
} | ||
|
||
func index(ctx iris.Context) { | ||
ctx.View("program.html", iris.Map{ | ||
"Name": "Gerasimos", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/kataras/iris/v12" | ||
"github.com/kataras/iris/v12/view" | ||
) | ||
|
||
func main() { | ||
e := iris.Jet(nil, ".jet") // You can still use a file system though. | ||
e.AddFunc("greet", func(args view.JetArguments) reflect.Value { | ||
msg := "Hello, " + args.Get(0).String() + "!" | ||
return reflect.ValueOf(msg) | ||
}) | ||
err := e.ParseTemplate("program.jet", `<h1>{{greet(.Name)}}</h1>`) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
app := iris.New() | ||
app.RegisterView(e) | ||
app.Get("/", index) | ||
|
||
app.Listen(":8080") | ||
} | ||
|
||
func index(ctx iris.Context) { | ||
ctx.View("program.jet", iris.Map{ | ||
"Name": "Gerasimos", | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.