Monks,

I'm tired of writing meta code in templating languages. I'm really good at writing Perl, and good at writing HTML, but I'm lousy at the templating languages (and I'm not too fired up to learn more about them).

I'm tired of form handling. I have written form handling modules, and they always get way too complicated. But then tonight I had an idea.

That idea is Template::Empty. If this sound crazy, just keep reading. It gets weirder.

HTML pages are easy to parse (please ignore server side includes for this rfc). The problem happens when you mix code and html in attempting to make them easy to write. Mixing code and html has done to many a programmer what mixing booze and pills has done to many a rockstar. The end result is never pretty.

So I introduce to you the concept of the empty template:

<html> <head> <title></title> </head> <body> <div id="messagebar"></div> <p>Please fill out this form</p> <p> <form action=""> Userame: <input type='text' name='username' value=''> </p> <p><input type='submit' name='submit'></p> </form> </body> </html>

Note first off that the title tag is empty. So now we need a template object to fill that in:

my $template = Template::Empty->load(file =>'index.html'); $template->title = 'Now we have a page title'. $template->form->action = $ctx->uri; $template->form->username->value = $default_user->username; $template->messagebar = 'Your last record was updated'; print $template->as_string;

There you have it. The class parses the html file once on load, and constructs a template object containing entities such as title which can be set, and form objects which can be manipulated. There are certainly libraries such as HTML::FillInForm, and Template, which can be used to implement the actual as_string() method which serializes the template output.

Of course, I'm sure this approach is fraught with its own nasty design issues, but it allows for a pure html template in some simple cases examined here. Feedback welcome.


In reply to RFC - Template::Empty by redhotpenguin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.