如何在模板工具包(Template Toolkit)的模板文件中覆盖WRAPPER?

11
有没有一种方法可以通过模板或使用parse()进行临时覆盖来禁用在new(\%config)中设置的WRAPPER?我想要一个单一的默认WRAPPER(我将在99.9%的模板中使用它),但要排除一些模板。
我正在通过Catalyst::View::TT完成所有操作,就像configuration synopsis中的示例一样,只是我不希望WRAPPER应用于我的所有模板。
3个回答

8
编辑包装器,加入类似于这样的条件语句:
[% IF no_wrapper OR template.no_wrapper %] [% content %] [% ELSE %]
  top;
    [% content %]
  bottom;
[% END %]

这使我可以在模板内或从stash中禁用包装器,方法如下:
  1. [%- META no_wrapper = 1 -%]
  2. $c->stash->{no_wrapper} = 1
META var ...;是一个指令,使得var通过template.var变得可访问。
来源: http://wiki.catalystframework.org/wiki/gettingstarted/howtos/template_wrappers

1
这是使用此方法的样板XHTML 1.1包装器:http://github.com/EvanCarroll/Craiglickr/blob/master/root/wrapper.tt - Evan Carroll

4
site/wrapper本身中定义异常,顺便提一下那里已经有定义好的异常了。
[% IF template.name.match('\.(css|js|txt)');
     debug("Passing page through as text: $template.name");
     content;
   ELSE;
     debug("Applying HTML page layout wrappers to $template.name\n");
     content WRAPPER site/html + site/layout;
   END;
-%]

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接