Reputation: 66947
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?
Upvotes: 9
Views: 353
Reputation: 628
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>
Upvotes: 5
Reputation: 316
If you use that pragma in your Mojolicious App, it should work for the templates as well.
If not, then you could add it to a layout and use that layout from your templates.
Upvotes: 0