如何覆盖 Template Toolkit 模板文件中的 WRAPPER?

发布于 2024-08-22 14:36:06 字数 461 浏览 11 评论 0原文

有没有办法禁用 new(\%config),通过模板还是使用 parse() 进行临时覆盖?我想要一个默认的 WRAPPER(我将用于 99.9% 的模板),但排除一些。

我通过 Catalyst::View::TT 完成这一切,就像 配置概要,但我不希望 WRAPPER 应用于我的所有模板。

Is there a way to disabling a WRAPPER that was set in new(\%config), through either the template, or a temporary override with parse()? I want to have a single default WRAPPER (that I'll use for 99.9% of my templates), but exclude a few.

I'm doing this all through Catalyst::View::TT just like the example in the configuration synopsis, except I don't want the WRAPPER to apply to all of my templates.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

薯片软お妹 2024-08-29 14:36:06

编辑包装器,以包含如下条件:

[% IF no_wrapper OR template.no_wrapper %] [% content %] [% ELSE %]
  top;
    [% content %]
  bottom;
[% END %]

这允许我禁用包装器(1)在模板内部,或(2)从存储中。

  1. [%- META no_wrapper = 1 -%]
  2. $c->stash->{no_wrapper} = 1

META var ...; > 是一个指令,使 var 通过 template 哈希作为 template.var

源进行访问:http://wiki.catalystframework.org/wiki/gettingstarted/howtos/template_wrappers

Edit the wrapper, to include a conditional like:

[% IF no_wrapper OR template.no_wrapper %] [% content %] [% ELSE %]
  top;
    [% content %]
  bottom;
[% END %]

This allows me to disable the wrapper either (1) inside of template, or (2) from the stash.

  1. [%- META no_wrapper = 1 -%]
  2. $c->stash->{no_wrapper} = 1

META var ...; is a directive that makes var accessible through the template hash as template.var

source: http://wiki.catalystframework.org/wiki/gettingstarted/howtos/template_wrappers

时间你老了 2024-08-29 14:36:06

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;
-%]

Define exceptions in site/wrapper itself, and btw there are exceptions defined there already.

[% 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;
-%]
扶醉桌前 2024-08-29 14:36:06

我偶然遇到了同样的问题,并创建了一个更通用的解决方案,允许动态切换布局,或者根本没有布局。请参阅此处:

多个布局/包装器舞者和模板::工具包

I stumbled into the same problem, and created a more generalized solution that allows for dynamic switching of layouts, or to have no layout at all. See here:

More than one layout/wrapper with Dancer and Template::Toolkit

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文