Felix Sun
unread,Jun 27, 2012, 5:14:00 AM6/27/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to golan...@googlegroups.com
Say I have 3 templates:
1. index.tpl
2. _post.tpl
3. _comment.tpl
and the data structure is like:
type IndexData struct {
Posts []*Post
}
type Post struct {
Comments []*Comment
CreatedAt time.Time
}
type Comment struct {
CreatedAt time.Time
}
Note that I render a collection of Posts inside index.tpl like this:
{{range .Posts}}
{{template "post" .}}
{{end}}
and Inside _post.tpl I render a collection of comments:
{{range .Comments}}
{{template "comment" .}
{{end}}
So the problem is, I need to show the Creation date of the posts and
the comments according to Logged in user's Timezone, different user
seems different format for the same actual time value. The template
will be like this:
{{.CreatedAtInTimezone $loggedInUser.Timezone }}
And It doesn't feel right If I put the LoggedInUser's Timezone info
object into all IndexData and Post and Comment struct and set the
value in Loop before rendering the templates,
So how can I get the LoggedInUser info inside the 3 templates?