Comments (1)
Yes @rebootcode because you're trying to use a template function instead of printing something, in golang we use the {{.property_name}}
to print a binded value. Even the Iris' README.md overview html and go source code shows that-- https://github.com/kataras/iris/blob/master/README.md#-installation but it's ok, you have to watch the iris project in order to not miss the good tricks in golang+web.
See the first dot(.)
Welcome {{.user.Name}}
A trivial example:
./main.go
package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/sessions"
)
type User struct {
ID int64
Name string
}
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html"))
sess := sessions.New(sessions.Config{Cookie: "sessionid"})
app.Get("/login", func(ctx iris.Context) {
var testUser = User{Name: "iris"}
session := sess.Start(ctx)
session.Set("user", testUser)
})
app.Get("/", func(ctx iris.Context) {
session := sess.Start(ctx)
testUser := session.Get("user")
ctx.ViewData("user", testUser)
ctx.View("index.html")
})
app.Run(iris.Addr(":8080"))
}
./views/index.html
<html>
<head>
<title>Welcome {{.user.Name}}</title>
</head>
<body>
<h1>Welcome {{.user.Name}} | Logout</h1>
</body>
</html>
Even if it's not a good idea to store the whole user data in session, usually I store just the user's ID and fetch the whole user when I need it.
from examples.
Related Issues (20)
- Any example of this code??? HOT 1
- read form example cannot run HOT 1
- Gzip doesn't work HOT 2
- Flash Session [ Help Needed ] HOT 1
- get with params HOT 2
- how to read data from client like JMeter HOT 4
- why static file can't be packaged HOT 5
- Can we use mvc service in another service? HOT 3
- How can I get test coverage? HOT 1
- "WithoutVersionChecker" is undefined! HOT 2
- "Hello, webAssembly" link in the table of contents is broken HOT 1
- Error with ctx.URLParams()
- write tcp [::1]:8099->[::1]:64820: wsasend: An established connection was aborted by the software in your host machine.
- WebSocket to REST handlers Adapter
- /create and /decode has no function at the example "Glimpse" HOT 1
- html/template: "movie/index.html" is undefined HOT 1
- Potential import collision: import path should be "go.etcd.io/bbolt", not "github.com/etcd-io/bbolt" HOT 4
- httpexpect doesn't work
- How do I set up a header? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from examples.