简体   繁体   中英

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, 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

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.

我将为Template-Toolkit切换出HTML :: Template并使用它的WRAPPER指令。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM