HTMLTemplateProRenderer, a form of templating for Mojolicious

perl code To create websites the language of "programming" is called HTML but this allows you to write only static pages in the sense of the content pages that do not change over time unless someone does not go hand in changing the HTML code.

To create sites that dynamically change their content is necessary to integrate the HTML with a "program" that runs every time someone calls the page, it generates the HTML from time to time creating new content.

But to leave separate the role of the programmer from the one that writes the HTML page systems exist, said web, whereby is created an HTML page "skeleton" of which, in turn, the program inserts the dynamic content.

Let's say I want to display a page in the temperature outside. We can write something like:

"Hello. Currently out there are degrees xxx"

and give this meal in a program that replaces the placeholder "xxx" the present value taken in some way so that, every time someone calls this web page, the program takes the template that we wrote above, we obtain the outdoor temperature by some apparatus, it puts the value in place of the "xxx" and returns the full text to your browser.

A few years ago I contributed to writing a few pieces for the templating system HTML :: Template :: Pro

HTP_Authors and created a modular extension plugin for this module called HTML :: Template :: Pro :: Extension.

These modules allow you to use placeholders like% name%,% name%,%% temperature which are then replaced with their real values ​​passed from the program.

Since in this hot summer I'm having a little 'fiddling with Mojolicious , a framework for web applications in real time which of course has a its templating system to integrate HTML code and dynamically generated code, I thought, why not create a Mojolicious module to integrate with HTML :: Template :: Pro and :::::: Extension?

And so was born Mojolicious :: Plugin :: HTMLTemplateProRenderer that integrates precisely in Mojolicious these two templating systems.

So, you can now write code like this

use Mojolicious::Lite;
plugin 'HTMLTemplateProRenderer';
 
get '/hello/#cometichiami' => sub{
  my $c = shift;
  $c->render('hello', handler => 'tmpl');
}

__DATA__

@@ hello.html.tmpl
Ciao %cometichiami%

e vedere sul browser un bel saluto :-)

Il modulo è stato citato anche nel " What's new on CPAN " di Luglio 2014 su perltricks.

 

Lascia un Commento

L'indirizzo email non verrà pubblicato. I campi obbligatori sono contrassegnati *

È possibile utilizzare questi tag ed attributi XHTML : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>