Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2457)

Issue 6447044: {{block}} support in text/template

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 9 months ago by rodrigo.moraes
Modified:
11 years, 8 months ago
Reviewers:
Visibility:
Public.

Description

This adds two new actions to text/template: {{block}} and {{fill}}. This is how it works: The content of a {{block}} action is displayed normally when a template is called directly. But when the template is inserted into another one using a {{fill}} action, the blocks can be replaced by blocks with the same name defined in the fill action. Nutshell example: {{define "Base"}} <p>{{block "body"}} A body. {{end}}</p> {{end}} {{define "Home"}} {{fill "Base"}} {{block "body"}} Another body. {{end}} {{end}} {{end}} {{define "Item"}} {{fill "Base"}} {{block "body"}} And yet another body. {{end}} {{end}} {{end}} Executing the templates "Base", "Home" and "Item" results in: "<p>A body</p>", "<p>Another body</p>" and "<p>And yet another body</p>". Essentially, {{fill}} behaves like a {{template}} action with body: {{block}} actions that replace the ones in the called template. The idea is to use this to define layout skeletons filled in different templates. In practical terms this works like "template inheritance" in Django templates -- but this schema is based in composition rather than inheritance. Try the new actions in the package: code.google.com/p/sadbox/template

Patch Set 1 : Added tests involving dot variables and if's. #

Patch Set 2 : updated mechanics; {{fill}} behaves like a special {{template}} with child nodes #

Patch Set 3 : disallow nodes that generate output inside a {{fill}}, except {{block}} #

Patch Set 4 : added {{block}} and {{fill}} to html/template #

Unified diffs Side-by-side diffs Delta from patch set Stats (+392 lines, -4 lines) Patch
A src/pkg/html/template/block_test.go View 1 2 3 1 chunk +98 lines, -0 lines 0 comments Download
M src/pkg/html/template/escape.go View 1 2 3 1 chunk +4 lines, -0 lines 0 comments Download
A src/pkg/text/template/block_test.go View 1 2 1 chunk +98 lines, -0 lines 0 comments Download
M src/pkg/text/template/exec.go View 1 2 3 chunks +67 lines, -4 lines 0 comments Download
M src/pkg/text/template/parse/lex.go View 1 3 chunks +6 lines, -0 lines 0 comments Download
M src/pkg/text/template/parse/node.go View 1 2 2 chunks +80 lines, -0 lines 0 comments Download
M src/pkg/text/template/parse/parse.go View 1 2 2 chunks +39 lines, -0 lines 0 comments Download

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b