view

package
v0.0.0-...-f5f780e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 12, 2013 License: BSD-2-Clause Imports: 12 Imported by: 4

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

type View struct {
	ResourcePrefix string
	Watch          bool
	// contains filtered or unexported fields
}

View manages the whole template system.

func NewView

func NewView(root string) *View

NewView returns a new View with the given location of the template folder.

func (*View) AddFunc

func (v *View) AddFunc(name string, f interface{}) error

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) Load

func (v *View) Load(w io.Writer, pageName string, data interface{}) error

Load render the template you specific with name and write it to the Writer.W

func (*View) Parse

func (v *View) Parse(set string) error

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

func (v *View) SetDefault(set string) error

SetDefault change the set to default. It call Parse if need.

func (*View) SetLang

func (v *View) SetLang(l *locale.Lang)

SetLang set the language use with the current template system. The method must be call before Parse. After call this method you can use these command in your .tmpl files:

{{lang "filename.lang" "key"}}
{{langset "set" "filename.lang" "key"}}

type ViewData

type ViewData map[string]interface{}

func NewViewData

func NewViewData(title string) ViewData

func (ViewData) AddScripts

func (data ViewData) AddScripts(paths ...string) ViewData

func (ViewData) AddStrings

func (data ViewData) AddStrings(key string, paths ...string) ViewData

func (ViewData) AddStyle

func (data ViewData) AddStyle(paths ...string) ViewData

func (ViewData) SetTitle

func (data ViewData) SetTitle(title string) ViewData

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL