Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Embeding Perl in HTML the PHP way

by davido (Archbishop)
on Sep 11, 2012 at 19:20 UTC ( #993039=note: print w/ replies, xml ) Need Help??


in reply to Embeding Perl in HTML the PHP way

I know of no simpler solution than what is provided by a Mojolicious::Lite framework (see the Mojolicious website).

#!/usr/bin/env perl use Mojolicious::Lite; get '/index' => sub { my $self = shift; $self->render('index', some_string => "Hello world!!!" ); }; app->start; __DATA__ @@ index.html.ep <!DOCTYPE html> <html> <head> <title>Hello world</title> </head> <body> <%= $some_string %> </body> </html>

Let's say you call that "myapp.pl". Run it like this: ./myapp.pl daemon. Point your browser to http://localhost:3000/index.html.

Deployment options are covered here: Mojolicious::Guides::Cookbook#DEPLOYMENT.

This is a minimal example. In a real app you would want to reduce the redundancy somewhat between templates by using layouts. And you would define more routes, of course. ...and probably set index up as a default fallback route. For example:

get '/goodbye' => sub { $_[0]->render( 'goodbye', some_string => "Goodbye world!" ); }; get '/*fallback' => { fallback => 'index' } => sub { $_[0]->render( 'index', some_string => "Hello world!\n" ); }; __DATA__ @@ index.html.ep ........ @@ goodbye.html.ep ...........

The fallback is defined as your last route so that it doesn't try to take over unless no other routes matched. Also you would probably eventually inflate the app so that the templates can each live in their own files. Any pages that are truly static content will reside in public/.


Dave


Comment on Re: Embeding Perl in HTML the PHP way
Select or Download Code
Re^2: Embeding Perl in HTML the PHP way
by heatblazer (Scribe) on Sep 11, 2012 at 19:23 UTC

    Thank, you, I`ll add it to my todo list for testing

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993039]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (12)
As of 2014-07-24 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (165 votes), past polls