in reply to Dancer and Template-Toolkit

G'day nathaniels,

Welcome to the monastery.

It's been a few years since I last used Template::Toolkit and I haven't used Dancer. Bearing those caveats in mind, your main problem seems to be this:

FOREACH item IN list

which, from the examples in Template::Manual::Intro, should be:

FOREACH item = list

You also have secondary problems in your HTML code: <title> should be in a <head> element; <h1> and <h2> should be inside the <body> element; and <li> should be in a <ul> element. I'd suggest your template should look a bit more like this:

<html> <head> <title>...</title> </head> <body> <h1>...</h1> <h2>...</h2> <ul> <% FOREACH item = list %> <li><% item %></li> <% END %> </ul> </body> </html>

Some browsers may be forgiving about this but not necessarily consistently and it's not something you should rely on.

-- Ken

Replies are listed 'Best First'.
Re^2: Dancer and Template-Toolkit
by tobyink (Canon) on Sep 09, 2013 at 00:24 UTC

    "<title> should be in a <head> element; <h1> and <h2> should be inside the <body>..."

    Allow me to blow your mind... they already are!

    Many HTML elements have optional closing tags. For example:

    <p>Foo <p>Bar

    When an HTML parser encounters the second opening <p> tag, it can infer that the first <p> element must have closed, because paragraphs cannot be legitimately nested. (Well, actually they can if you use the right interleaving elements, but that's another story...)

    This is not just browsers being forgiving. It's part of the HTML spec; even allowed by the strict versions of HTML. (But not by XHTML obviously, which is an entirely different kettle of fish altogether.)

    Now, here's the mindblowing bit. And it relies on you being able to divorce tags and elements a little in your mind. We've seen how an element can legitimately exist without a closing tag; it's also possible for an element to exist without an opening tag!

    Given the following:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <title>Foo</title> <p>Bar</html>

    ... when a parser encounters the <title> tag, it infers that not only the <title> element has been opened, but that <html> and <head> have too. When it encounters <p> it infers that <head> must have closed (because <p> cannot be used within <head>) and <body> must have begun.

    The Foo Bar document above is a complete, valid HTML 4.01 Strict document. Don't believe me?

    spec ref

    Now, you could argue that omitting optional start tags is bad style. I might even agree with you. But it's very, very common. (Hint: take a look at the content model for the <table> element.)

    use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name
Re^2: Dancer and Template-Toolkit
by nathaniels (Acolyte) on Sep 08, 2013 at 03:40 UTC
    Ah. Thank you for your speedy reply!