I don"t want to write an HTML templating module
I don"t want to write an HTML templating module
am 30.08.2007 11:27:03 von Hayden Stainsby
Like many Perl developers at one stage or another I'm thinking of
writing an HTML templating module. Of course I know this is a bad
idea, there's plenty of really good ones about. I don't want to, so...
Are there any Perl modules about that do HTML templating like Apache's
Tapestry for Java? Specifically a way of doing HTML templating that
keeps your HTML completely separate from your code. So there's no code
in the template at all, but rather the module reads the template and
then uses it to format the data it has.
The main advantage for this is that a designer who knows (and wants to
know) nothing of programming can create the template, and the
programmer can write the code and crossover between these two tasks
can be mostly removed.
Thanks.
--
Hayden
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: I don"t want to write an HTML templating module
am 30.08.2007 11:58:55 von Gunnar Hjalmarsson
Hayden Stainsby wrote:
> Are there any Perl modules about that do HTML templating
http://search.cpan.org/search?query=HTML+template
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: I don"t want to write an HTML templating module
am 30.08.2007 12:35:55 von Hayden Stainsby
In article <5jnin3Fbi4aU1@mid.individual.net> Gunnar
Hjalmarsson wrote:
> Hayden Stainsby wrote:
>> Are there any Perl modules about that do HTML templating
> http://search.cpan.org/search?query=HTML+template
I'm sorry for not making my aims more specific. I'm looking for a
system that allows a template to contain nothing that isn't HTML,
basically a page that can be rendered by a web browser - more an
example page in static HTML than a template in some ways. So there
aren't any control structures in the HTML - tapestry uses a few (not
strictly HTML) attribute such as 'jwcid' in some tags so they can be
referenced later.
So an HTML template snippet like this:
Could be linked to a Perl array via it's id 'list_item':
qw(Cars Planes Boats Boats Space-ships)
and an output like (the non-html jwcid attribute is removed):
- Cars
- Planes
- Boats
- Boats
- Space-ships
I've looked through pretty much every html templating release on CPAN
and can't find anything myself, which is why I'm asking here.
Thanks.
--
Hayden
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: I don"t want to write an HTML templating module
am 30.08.2007 16:59:30 von merlyn
>>>>> "Hayden" == Hayden Stainsby writes:
Hayden> I'm sorry for not making my aims more specific. I'm looking for a
Hayden> system that allows a template to contain nothing that isn't HTML,
Hayden> basically a page that can be rendered by a web browser - more an
Hayden> example page in static HTML than a template in some ways. So there
Hayden> aren't any control structures in the HTML - tapestry uses a few (not
Hayden> strictly HTML) attribute such as 'jwcid' in some tags so they can be
Hayden> referenced later.
And that makes it not HTML. If you're already crossing the line, cross
it completely. Don't pretend you're not crossing it. :)
Hayden> So an HTML template snippet like this:
Hayden>
Hayden> - Jackets
Hayden> - Shirts
Hayden> - Ties
Hayden>
And that's not HTML. You might as well write:
[% list = ['Jackets' 'Shirts' 'Ties'] %]
[% FOR item IN list %]
[% "" IF loop.first %]
- [% item %]
[% "
" IF loop.last %]
[% END # foreach %]
And life is good. :-)
print "Just another Perl hacker,"; # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
Posted via a free Usenet account from http://www.teranews.com
Re: I don"t want to write an HTML templating module
am 30.08.2007 18:40:59 von Hayden Stainsby
In article <864pih131p.fsf@blue.stonehenge.com>
merlyn@stonehenge.com(Randal L. Schwartz) wrote:
> And that makes it not HTML. If you're already crossing the line,
> crossit completely. Don't pretend you're not crossing it. :)
There's still a big difference between what I have below, which will
display correctly most browsers and can be passed around as an example
of what a page will look like, and what's required when you have code
(even if it isn't perl code) inside the HTML.
I can give the former to anyone who knows HTML - or anyone who can
operate Dreamweaver - and they can edit it happily without knowing
what these extra attributes mean. The second however can only be
editted by someone who knows the syntax for HTML::Template - or
another templating module which works in a similar fashion.
> Hayden> So an HTML template snippet like this:
> Hayden>
> Hayden> - Jackets
> Hayden> - Shirts
> Hayden> - Ties
> Hayden>
> And that's not HTML. You might as well write:
> [% list = ['Jackets' 'Shirts' 'Ties'] %]
> [% FOR item IN list %]
> [% "" IF loop.first %]
> - [% item %]
> [% "
" IF loop.last %]
> [% END # foreach %]
But thanks for pointing out my stepping over lines and such. (-:
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: I don"t want to write an HTML templating module
am 30.08.2007 19:02:35 von xhoster
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Hayden" == Hayden Stainsby writes:
>
> Hayden> I'm sorry for not making my aims more specific. I'm looking for a
> Hayden> system that allows a template to contain nothing that isn't HTML,
> Hayden> basically a page that can be rendered by a web browser - more an
> Hayden> example page in static HTML than a template in some ways. So
> there Hayden> aren't any control structures in the HTML - tapestry uses a
> few (not Hayden> strictly HTML) attribute such as 'jwcid' in some tags so
> they can be Hayden> referenced later.
>
> And that makes it not HTML.
Both of the HTML renders I've viewed it with managed to render it. Does
the HTML standard declare unrecognized attributes to be illegal?
> If you're already crossing the line, cross
> it completely. Don't pretend you're not crossing it. :)
Or we could just have modules that DWIM, rather than being
fundamentalist/extremist.
>
> Hayden> So an HTML template snippet like this:
>
> Hayden>
> Hayden> - Jackets
> Hayden> - Shirts
> Hayden> - Ties
> Hayden>
>
> And that's not HTML. You might as well write:
>
> [% list = ['Jackets' 'Shirts' 'Ties'] %]
> [% FOR item IN list %]
> [% "" IF loop.first %]
> - [% item %]
> [% "
" IF loop.last %]
> [% END # foreach %]
>
> And life is good. :-)
Eh, I see a big difference between those. And I'd much rather write
the first rather than the second.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
Re: I don"t want to write an HTML templating module
am 31.08.2007 02:56:13 von Eric Berg
Hayden,
It sound like you may want to check out XSLT. I can imagine just
transforming the HTML that you're describing, though I haven't given
much thought to the effort involved in addressing your larger issue of
implementing your stuff in something that's supportable, etc.
If you just need to strip out certain attributes, that'd be really
simple. (Famous last words...)
Alternatively, you could mix XPATH and Perl. XPATH is the spec for
addressing XML documents cannonically. You could, for example, refer to
all UL lists and retrieve them to an array, and then process each of those.
Are you just trying to include instructions for humans in your HTML, or
are these processing instructions?
If you just want to be able to view raw templates in a browser, setting
your tag boundries to something innocuous, like comments could be an
approach for you.
-Eric.
Hayden Stainsby wrote:
> In article <864pih131p.fsf@blue.stonehenge.com>
> merlyn@stonehenge.com(Randal L. Schwartz) wrote:
>> And that makes it not HTML. If you're already crossing the line,
>> crossit completely. Don't pretend you're not crossing it. :)
>
> There's still a big difference between what I have below, which will
> display correctly most browsers and can be passed around as an example
> of what a page will look like, and what's required when you have code
> (even if it isn't perl code) inside the HTML.
>
> I can give the former to anyone who knows HTML - or anyone who can
> operate Dreamweaver - and they can edit it happily without knowing
> what these extra attributes mean. The second however can only be
> editted by someone who knows the syntax for HTML::Template - or
> another templating module which works in a similar fashion.
>> Hayden> So an HTML template snippet like this:
>
>> Hayden>
>> Hayden> - Jackets
>> Hayden> - Shirts
>> Hayden> - Ties
>> Hayden>
>
>> And that's not HTML. You might as well write:
>
>> [% list = ['Jackets' 'Shirts' 'Ties'] %]
>> [% FOR item IN list %]
>> [% "" IF loop.first %]
>> - [% item %]
>> [% "
" IF loop.last %]
>> [% END # foreach %]
>
> But thanks for pointing out my stepping over lines and such. (-:
>
>
Re: I don"t want to write an HTML templating module
am 31.08.2007 07:44:26 von merlyn
>>>>> "xhoster" == xhoster writes:
xhoster> Both of the HTML renders I've viewed it with managed to render it. Does
xhoster> the HTML standard declare unrecognized attributes to be illegal?
Yes.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
Posted via a free Usenet account from http://www.teranews.com
Re: I don"t want to write an HTML templating module
am 31.08.2007 11:19:32 von Hayden Stainsby
In article <46D7672D.70007@bergbrains.com> Eric
Berg wrote:
> Hayden,
> It sound like you may want to check out XSLT. I can imagine just
> transforming the HTML that you're describing, though I haven't given
> much thought to the effort involved in addressing your larger issue
> of implementing your stuff in something that's supportable, etc.
> If you just need to strip out certain attributes, that'd be really
> simple. (Famous last words...)
I've used XSLT previously - although only for creating XSL-FO, I'll
have look into it and see how well I can make it mash the data that I
want together.
> Alternatively, you could mix XPATH and Perl. XPATH is the spec for
> addressing XML documents cannonically. You could, for example, refer
> to all UL lists and retrieve them to an array, and then process each
> of those.
> Are you just trying to include instructions for humans in your HTML,
> or are these processing instructions?
> If you just want to be able to view raw templates in a browser,
> setting your tag boundries to something innocuous, like comments
> could be an approach for you.
I'm just after instructions for machine processing, but the catch is
the template should look exactly the same as a page would in a browser
- providing you fill it in with appropriate sample data. Elsewhere in
this thread the semantics of what constitutes HTML are being
discussed, however what I'm interested in is what a browser displays -
and we all know that most browsers are far more leniant than the HTML
spec.
So, in an ideal world a web developer makes me a template. It consists
of a page heading, a list and a table with three columns and some
number of rows more than 1. Attributes are added (in this case 'myid')
to the important tags to let the processor know that they're the same
- but they won't effect the way a page is displayed in most web
browsers:
Sample heading
Item 1 |
Item 2 |
Item 3 |
Item 4 |
Item 5 |
Item 6 |
Now I take my data. I have a page title which I link to
myid="heading1" and that gets substituted in there.
I also have a list of 18 (because I only want multiples of 3) names of
items, I link this to both myid="list1" and myid="tcell1" and my
output will go and give me an un-numbered list with my 18 items in it,
and a table with the same 18 items - split into 6 rows each with 3
cells on the row, because that's what my template looked like.
As I said to begin with - I'm just looking to see if there's a way of
doing this in an existing module, I know it's kind of a big ask.
I'll go look at XSLT/XPATH in more depth now, thanks.
--
Hayden
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: I don"t want to write an HTML templating module
am 31.08.2007 13:28:47 von Peter Scott
On Thu, 30 Aug 2007 16:40:59 +0000, Hayden Stainsby wrote:
> There's still a big difference between what I have below, which will
> display correctly most browsers and can be passed around as an example
> of what a page will look like, and what's required when you have code
> (even if it isn't perl code) inside the HTML.
>
> I can give the former to anyone who knows HTML - or anyone who can
> operate Dreamweaver - and they can edit it happily without knowing
> what these extra attributes mean. The second however can only be
> editted by someone who knows the syntax for HTML::Template - or
> another templating module which works in a similar fashion.
I don't see how that's any different from someone having to learn the
syntax for Tapestry, like the example I found at
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/si te/resources/t5-tutorial.pdf?revision=552890
${message}
Guess a number between one and ten:
${index}
They still have to know about all the tags.
I have used HTML::Template on a project where the HTML editing person used
Dreamweaver. I just made bare bones pages for them and explained the
function of the , , and tags in about five
minutes so they knew how they could move them around. This was a very
successful arrangement; I never had to look at the HTML layout except
on rare occasions when the behavior changed.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
Re: I don"t want to write an HTML templating module
am 31.08.2007 13:49:49 von Hayden Stainsby
In article Peter
Scott wrote:
> On Thu, 30 Aug 2007 16:40:59 +0000, Hayden Stainsby wrote:
>> There's still a big difference between what I have below, which
>> will display correctly most browsers and can be passed around as an
>> example of what a page will look like, and what's required when you
>> have code (even if it isn't perl code) inside the HTML.
>>
>> I can give the former to anyone who knows HTML - or anyone who can
>> operate Dreamweaver - and they can edit it happily without knowing
>> what these extra attributes mean. The second however can only be
>> editted by someone who knows the syntax for HTML::Template - or
>> another templating module which works in a similar fashion.
> I don't see how that's any different from someone having to learn
> thesyntax for Tapestry, like the example I found at
> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/si te/resourc
> es/t5-tutorial.pdf?revision=552890
>
>
>
> ${message}
>
>
> Guess a number between one and ten:
>
> ${index}
>
>
> They still have to know about all the tags.
My apologies, looks like tapestry doesn't always behave exactly the
way I thought it did, I've not actually used it myself. Of course now
I look like an idiot, but the way I've seen it working is without any
of the tags.
You define attributes and then the Java code handles all the control -
so there aren't any control structures in the HTML - just plain HTML
(excluding these attributes, which are ignored my most browsers).
I've posted an example of the functionality I originally looking for
further down in response to Eric Berg's post.
--
Hayden
--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo
Re: I don"t want to write an HTML templating module
am 31.08.2007 20:43:48 von hjp-usenet2
On 2007-08-30 17:02, xhoster@gmail.com wrote:
> merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>> >>>>> "Hayden" == Hayden Stainsby writes:
>>
>> Hayden> I'm sorry for not making my aims more specific. I'm looking for a
>> Hayden> system that allows a template to contain nothing that isn't HTML,
>> Hayden> basically a page that can be rendered by a web browser - more an
>> Hayden> example page in static HTML than a template in some ways. So
>> there Hayden> aren't any control structures in the HTML - tapestry uses a
>> few (not Hayden> strictly HTML) attribute such as 'jwcid' in some tags so
>> they can be Hayden> referenced later.
>>
>> And that makes it not HTML.
>
>
> Both of the HTML renders I've viewed it with managed to render it. Does
> the HTML standard declare unrecognized attributes to be illegal?
Yes, but
* There has always been an understanding that HTML processing programs,
in particular user agents, should cope gracefully with errors and
extensions. For example, the HTML 4.01 recommendation says this:
| B.1 Notes on invalid documents
|
| This specification does not define how conforming user agents handle
| general error conditions, including how user agents behave when they
| encounter elements, attributes, attribute values, or entities not
| specified in this document.
|
| However, to facilitate experimentation and interoperability between
| implementations of various versions of HTML, we recommend the following
| behavior:
|
| * If a user agent encounters an element it does not recognize, it
| should try to render the element's content.
| * If a user agent encounters an attribute it does not recognize, it
| should ignore the entire attribute specification (i.e., the
| attribute and its value).
| * If a user agent encounters an attribute value it doesn't
| recognize, it should use the default attribute value.
| * If it encounters an undeclared entity, the entity should be
| treated as character data.
|
| We also recommend that user agents provide support for notifying the
| user of such errors.
The first point is actually quite hard to implement: If you don't know
an element, you don't know what its content is. But attributes are
syntactically unambiguous, so the only programs likely to choke on
undefined attributes are validators (that's what they are there for).
* You aren't writing HTML, you are writing input for a template engine.
So there is no reason why the files you are writing need to conform to
HTML. They only need to be acceptable to your template engine and to
your authoring tools.
>> Hayden> So an HTML template snippet like this:
>>
>> Hayden>
>> Hayden> - Jackets
>> Hayden> - Shirts
>> Hayden> - Ties
>> Hayden>
>>
>> And that's not HTML. You might as well write:
>>
>> [% list = ['Jackets' 'Shirts' 'Ties'] %]
>> [% FOR item IN list %]
>> [% "" IF loop.first %]
>> - [% item %]
>> [% "
" IF loop.last %]
>> [% END # foreach %]
>>
>> And life is good. :-)
If that's your idea of a good life, I don't want to know what you
consider a bad life.
> Eh, I see a big difference between those. And I'd much rather write
> the first rather than the second.
Same here.
hp
--
_ | Peter J. Holzer | I know I'd be respectful of a pirate
|_|_) | Sysadmin WSR | with an emu on his shoulder.
| | | hjp@hjp.at |
__/ | http://www.hjp.at/ | -- Sam in "Freefall"
Re: I don"t want to write an HTML templating module
am 01.09.2007 15:57:42 von Peter Scott
On Fri, 31 Aug 2007 11:49:49 +0000, Hayden Stainsby wrote:
> In article Peter
> Scott wrote:
>> I don't see how that's any different from someone having to learn
>> thesyntax for Tapestry, like the example I found at
>
>> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/si te/resourc
>> es/t5-tutorial.pdf?revision=552890
>
>>
>>
>>
>> ${message}
>>
>>
>> Guess a number between one and ten:
>>
>> ${index}
>>
>>
>
>> They still have to know about all the tags.
>
> My apologies, looks like tapestry doesn't always behave exactly the
> way I thought it did, I've not actually used it myself. Of course now
> I look like an idiot, but the way I've seen it working is without any
> of the tags.
>
> You define attributes and then the Java code handles all the control -
> so there aren't any control structures in the HTML - just plain HTML
> (excluding these attributes, which are ignored my most browsers).
So your program won't ever want to output a variable number of output
elements, like, say, rows in a table? Sounds pretty elementary. But most
applications do want to do that, and so they need control structures. If
you want to output one table row for each hit on a search, you're going to
have something like