Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-24 00:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found