Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 "". Run it like this: ./ 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/.


Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://993039]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2017-03-29 19:13 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (352 votes). Check out past polls.