yield

package
v0.0.0-...-acb45aa Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2013 License: BSD-2-Clause Imports: 12 Imported by: 0

Documentation

Overview

This library allows you to use yields and layouts similar to the Rails implementation for the current Revel template implementation.

In your app.conf, add a line like module.yield=github.com/acsellers/yield

Then instead of starting your controllers from *revel.Controller, you can import "github.com/acsellers/yield/app/controllers" and then use the struct yield.Controller to embed into your controllers.

Note: the module in that import path is named yield not controllers, and that is why you embed yield.Controller not controllers.Controller.

The booking sample from revel was ported to use the basic yield mechanism and is available in the samples directory.

Index

Constants

This section is empty.

Variables

View Source
var (
	LayoutPath    = "app/layouts"
	DefaultLayout = make(map[string]string)
)

To set your directory for loading layouts from, set the LayoutPath variable to the location relative to the base of your revel directory. You can only set one directory at the moment.

To set a default layout, take the format you wish that layout to apply for, i.e. "html", then set that string to the name of the layout you want to render.

Functions

This section is empty.

Types

type Controller

type Controller struct {
	*revel.Controller
	RenderTmpl map[string]revel.Template
	LayoutPath string
	// contains filtered or unexported fields
}

You can embed this Controller into your controllers instead of *revel.Controller, note that unlike revel.Controller, you do not need to embed a pointer to this controller.

func (*Controller) ContentFor

func (lc *Controller) ContentFor(yieldName, templateName string) error

Set a template from your main revel Template library to be rendered into a named yield.

func (*Controller) Layout

func (lc *Controller) Layout(s string)

Set the layout to be rendered for the current action. Setting the layout to empty string will cause no layout to be rendered. No layout will be rendered if you did not set a Default layout for the current request format and you do not call this function to set a specific layout. You do not have to include the format for the template, that will be added, but adding it the format would not cause a problem.

func (*Controller) Render

func (lc *Controller) Render(extraRenderArgs ...interface{}) revel.Result

The same kind of function as calling Render on revel.Controller, except that this will pick up the Layout you specified and render that as well.

func (*Controller) RenderTemplateWithLayout

func (lc *Controller) RenderTemplateWithLayout(templatePath string) revel.Result

If you needed to use revel's RenderTemplate, this is similar, except it uses the Layout specified on the Controller. If you do not wish for a Layout to be rendered, you should use RenderTemplate which is available. This call expects an actual layout to be rendered, failing to provide one is an error.

type RenderLayoutTemplateResult

type RenderLayoutTemplateResult struct {
	Template   revel.Template
	Layout     revel.Template
	RenderArgs map[string]interface{}
	RenderTmpl map[string]revel.Template
}

This is the Result object passed to revel when you render a view with a Layout set. RenderTmpl is the Templates that were set with ContentFor. Layout is the set Layout. Otherwise it is the same as revel's RenderTemplateResult. This actually doesn't require a Layout to be set, not that its used with that functionality.

func (*RenderLayoutTemplateResult) Apply

func (r *RenderLayoutTemplateResult) Apply(req *revel.Request, resp *revel.Response)

Render the Templates into the Response, handles errors and panics using the same mechanisms of revel.

Jump to

Keyboard shortcuts

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