Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2097299
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类:

2008-06-30 18:48:35

BLOCK

The BLOCK...END construct can be used to define template component blocks which can be processed with the INCLUDE, PROCESS and WRAPPER directives.

[% BLOCK tabrow %]

[% name %]
[% email %]

[% END %]


[% PROCESS tabrow name='Fred' email='fred@nowhere.com' %]
[% PROCESS tabrow name='Alan' email='alan@nowhere.com' %]

A BLOCK definition can be used before it is defined, as long as the definition resides in the same file. The block definition itself does not generate any output.

[% PROCESS tmpblk %]

[% BLOCK tmpblk %] This is OK [% END %]

You can use an anonymous BLOCK to capture the output of a template fragment.

[% julius = BLOCK %]
And Caesar's spirit, ranging for revenge,
With Ate by his side come hot from hell,
Shall in these confines with a monarch's voice
Cry 'Havoc', and let slip the dogs of war;
That this foul deed shall smell above the earth
With carrion men, groaning for burial.
[% END %]

Like a named block, it can contain any other template directives which are processed when the block is defined. The output generated by the block is then assigned to the variable julius.

Anonymous BLOCKs can also be used to define block macros. The enclosing block is processed each time the macro is called.

[% MACRO locate BLOCK %]
The [% animal %] sat on the [% place %].
[% END %]

[% locate(animal='cat', place='mat') %] # The cat sat on the mat
[% locate(animal='dog', place='log') %] # The dog sat on the log
阅读(1126) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~