Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const RootTemplateName = "root"
Variables ¶
This section is empty.
Functions ¶
func EnableAutoReparse ¶
func EnableAutoReparse()
func StopAutoReparse ¶
func StopAutoReparse()
Types ¶
type HtmlView ¶
type HtmlView struct {
// contains filtered or unexported fields
}
Represents a single html/template template. Encapsulate the template pathname from controller action code and allows further subviews based on this view.
Example ¶
package main
import "io"
import "os"
import "net/http/httptest"
import . "github.com/zaiuz/views"
import "github.com/zaiuz/testutil"
var ParentView = NewHtmlView("./testviews/example-parent.html")
type ParentViewData struct {
Title string
}
var ChildView = ParentView.Subview("./testviews/example-child.html")
type ChildViewData struct {
*ParentViewData
Content string
}
func main() {
parent := &ParentViewData{Title: "ExampleRender Test Title"}
child := &ChildViewData{
ParentViewData: parent,
Content: "The quick brown fox jumps over the lazy dog.",
}
context := testutil.NewTestContext()
ChildView.Render(context, child)
recorder := context.ResponseWriter.(*httptest.ResponseRecorder)
io.Copy(os.Stdout, recorder.Body)
}
Output: <html> <head> <title>ExampleRender Test Title</title> </head> <body> <h1>ExampleRender Test Title</h1> <p>The quick brown fox jumps over the lazy dog.</p> </body> </html>
func (*HtmlView) Render ¶
Renders the view to the response in the supplied Context with the given view data context.
func (*HtmlView) ReparseTemplate ¶
Click to show internal directories.
Click to hide internal directories.