Documentation
¶
Overview ¶
Package view implements a basic template system on top of html/template package. The package require a special structed folder like this example:
path/to/template/ ├── christmas │ ├── page1.tmpl │ ├── page2.tmpl │ └── shared │ ├── menu.tmpl │ └── layout.tmpl └── default ├── page1.tmpl ├── page2.tmpl └── shared ├── menu.tmpl └── layout.tmpl
Assuming your template folder located at path/to/template. There is some rules with this folder:
In the template folder should contain some sub-folder called view-set. Each view-set shloud contain some xyz.tmpl (where xyz is the file name) and a folder name "shared". In the "shared" folder must contain a file "layout.tmpl" (all the template file must end with .tmpl).
There is some rules for "xyz.tmpl" files:
All the contain of the file must in the {{define "page"}} ... {{end}} block. You can call the shared content (insert the content of the tmpl file in shared folder) by {{template "menu.tmpl"}} etc.
The "layout.tmpl" in shared folder is the main layout. The content of "xyz.tmpl" files should be embedded in this file. You must put {{template "page" .}} some where in this file.
For more detail, see the tutorial.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type View ¶
View manages the whole template system.
func (*View) AddFunc ¶
AddFunc add the function to the template system. You call call the function you added in the .tmpl files by {{function-name}}. An error return if you add an invalid function. Note: this function must be call before Parse.
func (*View) Parse ¶
Parse parses the view-set you want to use. You may call Parse for all view-set you have and then switching beetwen them by call SetDefault.
func (*View) SetDefault ¶
SetDefault change the set to default. It call Parse if need.
type ViewData ¶
type ViewData map[string]interface{}