Best way to build up XHTML

B

Bart van den Burg

Hi

I showed my code to someone a while ago, and he said that it's rather
unclean to have XHTML code within the Perl code. I must agree with this,
because it doesn't really look al that nice, but I don't really know how to
do it better.

I've been playing around with XML::Smart, only to find out it's not really
going to work, because it's rather hard to make constructions like <div>text
<a href="something">link</a> more text</div>, without putting each piece in
it's own element (i.e.: <div><span>text</span> <a
href="something">link</a><span>more text</span></div>). AFAIK, it's not even
possible.

Then I started to play a little with XML::DOM. Nice as well, but it seems to
miss out some important functions for use with XHTML, for example:
getElementById(), since this, of course, is only from (X)HTML, and not for
XML.

I'm wondering what the best way is. I'm not necessarily looking for a
module. Some other way might be nice as well, but it would be cool to be
able to change, for example, the <title>, or add some <meta> tags.

Any ideas?
Thanks!
 
S

Sherm Pendley

Bart said:
I showed my code to someone a while ago, and he said that it's rather
unclean to have XHTML code within the Perl code. I must agree with this,
because it doesn't really look al that nice, but I don't really know how
to do it better.

The most common approach is to use a "template" - an external file that
contains mostly (X)HTML, with a few placeholders that indicate where the
dynamic content goes. Your Perl script reads the template, replaces the
placeholders with the appropriate values, and sends the result to the
browser.

Search CPAN for "template" - there are many modules you can use. I've often
used Text::Template, because I like its simplicity. Mason does a lot more,
but by the same token it might be overkill for your needs.

sherm--
 
B

Bart van den Burg

Sherm Pendley said:
The most common approach is to use a "template" - an external file that
contains mostly (X)HTML, with a few placeholders that indicate where the
dynamic content goes. Your Perl script reads the template, replaces the
placeholders with the appropriate values, and sends the result to the
browser.

Search CPAN for "template" - there are many modules you can use. I've often
used Text::Template, because I like its simplicity. Mason does a lot more,
but by the same token it might be overkill for your needs.

sherm--

HTML::Template looks great actually! Mason is, as you say, a little
overkill.
I'll try out HTML::Template, thanks!

Bart
 
R

Richard Gration

HTML::Template looks great actually! Mason is, as you say, a little
overkill.
I'll try out HTML::Template, thanks!

Bart

I've been developing a complex website (~25000 lines of code, ~400
pages) for a few years using HTML::Template and have found it to be most
excellent. Other people have commented to me that it is a little on the
slow side. YMMV.

R
 
V

Vetle Roeim

Hi

I showed my code to someone a while ago, and he said that it's rather
unclean to have XHTML code within the Perl code. I must agree with this,
because it doesn't really look al that nice, but I don't really know how
to do it better.

Personally I prefer to build up XML in scripts (either by string
concatenation or using some XML module), and then transforming it with
XSLT to generate the final HTML or XHTML document. This has the added
benefit of making it easy for the people responsible for web design to
change it at will without bothering me. :) I guess this is also true if
you use some kind of templating.

[...]
 
V

Vetle Roeim

Personally I prefer to build up XML in scripts (either by string
concatenation or using some XML module), and then transforming it with
XSLT to generate the final HTML or XHTML document. This has the added
benefit of making it easy for the people responsible for web design to
change it at will without bothering me. :) I guess this is also true if
you use some kind of templating.

Just a small comment on this: One benefit of using XML is that
indepenendent modules (for an examples different components making up
different parts of web pages) can be created and their resulting XML
merged together.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top