Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use new syntax features in Mojolicious templates

I want to use fancy postfix dereferencing in my Mojo templates. I suppose I could do

% use experimental 'postderef';

at the top of every template file, but that seems repetitive and lame. Is there a way I can make Mojolicious import my pragma preferences to the lexical scope of every template?

like image 334
friedo Avatar asked Jul 20 '14 23:07

friedo


1 Answers

You can reload EPRenderer plugin with own options (default is without options), option template contains default values for Mojo::Template.

use Mojolicious::Lite;

plugin 'EPRenderer', template => { prepend  => 'use experimental "postderef";use Data::Dump "pp";'};

get '/' => sub { shift->render('index'); };

app->start;
__DATA__

@@ index.html.ep
% layout 'default';
% title 'Welcome';

Welcome to the Mojolicious real-time web framework!

% my $a = [[0]];
% push $a->[0]->@*, 1;
%=  pp($a)

@@ layouts/default.html.ep
<!DOCTYPE html>
<html>
  <head><title><%= title %></title></head>
  <body><%= content %>

  </body>
</html>
like image 183
vitas Avatar answered Nov 13 '22 19:11

vitas