开发者

separate layout from templates in perl cgi::application

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

I am using 7-8 different templates having the same layout - header, f开发者_如何学运维ooter, 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


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.


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜