将布局与 perl cgi::application 中的模板分开

发布于 2024-09-29 02:58:46 字数 182 浏览 1 评论 0原文

我正在使用 html::template 构建 perl cgi::application。

我使用 7-8 个具有相同布局的不同模板 - 页眉、页脚、左栏等。 如何将此 html 从模板文件中分离到单个布局文件中。除了 cgi::app 和 html::template 之外,我还需要哪些 Perl 模块。

谢谢

I am building a perl cgi::application using html::template.

I am using 7-8 different templates having the same layout - header, footer, left column etc.
How can I separate this html out of the template files into a single layout file. What perl modules do I need in addition to cgi::app and html::template.

Thanks

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

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

发布评论

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

评论(4

嘿哥们儿 2024-10-06 02:58:46

我同意 Template-Tookit 更好。

如果您绝对必须使用 HTML::Template 您可以使用 TMPL_INCLUDE 指令。它将搜索您定义的模板路径,或者您可以指定另一个模板的完整路径。它也会处理其中的变量。

您可以为页眉、页脚等创建单独的模板文件,并且在页面模板中只需 TMPL_INCLUDE 它们。它比 Template Toolkit 的 WRAPPER 不太优雅且重复性更高(对于所有共享元素,您必须在每个页面中多次使用 TMPL_INCLUDE),但它可以完成工作。

如果可以的话,请投入时间并使用模板工具包。

I agee that Template-Tookit is better.

If you absolutely have to use HTML::Template you can use the TMPL_INCLUDE directive. It'll search your defined template paths or you can specify a full path to another template. It'll process the variables in it as well.

You can create seperate template files for the header, footer and such and in your page templates just TMPL_INCLUDE them. It's less elegant and more repetative than Template Toolkit's WRAPPER (You'll have to TMPL_INCLUDE in each page several times for all shared elements) but it'll get the job done.

If you can, invest the time and use Template Toolkit.

澉约 2024-10-06 02:58:46

我会为 Template-Toolkit 切换 HTML::Template 并利用它的 WRAPPER 指令。

I'd switch out HTML::Template for Template-Toolkit and make use of it's WRAPPER directive.

本王不退位尔等都是臣 2024-10-06 02:58:46

我不知道模板工具包。所以我不会讨论哪种解决方案最方便。
我可以给你另一个解决方案,这取决于你运行 cgi 的服务器。
使用 Apache 服务器,您可以在 html 中使用包含:

<!--#include virtual="/includes/header/header.htm"-->

您可以调用 htm(静态页面)以及动态页面:

<!--#include virtual="/perl/includes/dynamic.pl"-->

但您必须进行一些 apache 调整。请参阅 Apache 教程:服务器端包含简介

希望这会有所帮助,或者至少给出一些想法

I don't know about Template-Toolkit. So i won't discuss about which solution is the most convenient.
I can just give you another solution, which is dependant of the server your running your cgi's on.
With Apache server, you can use includes in your html :

<!--#include virtual="/includes/header/header.htm"-->

you may call htm (static pages) as well as dynamic pages :

<!--#include virtual="/perl/includes/dynamic.pl"-->

but you have to do some apache tweaking. see Apache Tutorial: Introduction to Server Side Includes

Hope this will help, or at least give some ideas

_畞蕅 2024-10-06 02:58:46

不喜欢 HTML::Template 的人能说说为什么吗?虽然包装器的想法似乎对这个特定的海报有帮助,但包含的想法没有任何问题:它们更灵活,并且许多 Web 开发人员已经熟悉非动态发布的概念。

Can the people who don't like HTML::Template please say why? While the Wrapper idea seems helpful to this particular poster, there's nothing wrong with the idea of includes: they're more flexible, and many web developers will already be familiar with the concept from non-dynamic publishing.

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