Perl 6 module: Extra features on top of the default ::Mojo renderer for Bailador
Switch branches/tags
Nothing to show
Latest commit 6765fe9 Apr 27, 2017 @zoffixznet committed on GitHub Merge pull request #1 from samcv/SPDX-license
Use SPDX identifier in license field of META6.json
Failed to load latest commit information.
examples Final version May 1, 2016
lib/Bailador/Template/Mojo Toss newlines May 1, 2016
.gitignore Stuff Apr 30, 2016
.travis.yml First commit Apr 30, 2016
Changes Rework stash variables May 1, 2016
LICENSE First commit Apr 30, 2016
META6.json Use SPDX identifier in license field of META6.json Apr 27, 2017 Update May 4, 2016




WARNING: do not use this module. It currently has broken design that prevents template caching and the API will change, to address that issue.

Check back soon!


# in app.p6
use Bailador;
use Bailador::Template::Mojo::Extended;


get '/' => sub { template '', 'Zoffix', :name<Znet> }

# in views/layouts/
<!DOCTYPE html>
<title><%= $title %></title>
<div id="container">
    <%= $_content %>
<footer>Copyright (c) 2016</footer>

# in views/
%% title: Hello, World!
%% adjective: Awesome
<p><%= @pos[0] ~ ' ' ~ $name %> is <%= $adjective %>

# visit http://localhost:3000/ and get this:
<!DOCTYPE html>
<title>Hello, World!</title>
<div id="container">
    <p>Zoffix Znet is Awesome
<footer>Copyright (c) 2016</footer>


This module adds extra features to the default ::Mojo renderer.


renderer ... .new


Use Bailador's renderer sub to set up the new renderer backend by calling .new on Bailador::Template::Mojo::Extended class.


See Template::Mojo for general usage details. This module makes these modifications:

Layout templates

You can use base templates into which to include your regular templates:

    # views/layouts/
    <h1>This is HTML layout</h1>
    <%= $_content %>

    # views/layouts/
    <h1>This is EMAIL layout</h1>
    <%= $_content %>

    # views/

    # views/
    %% layout: email

    ## index template results in
    # <h1>This is HTML layout</h1>
    # <p>Foo</p>

    # email template results in
    # <h1>This is EMAIL layout</h1>
    # <p>Bar</p>

See examples/ directory for a working version of this sort of set up. The layout templates are located in views/layouts/ directory. They are set by either providing :layout named parameter to template Bailador sub or by using %% layout: at the start of the template.

Inside your layout, $_content variable contains the content of the template you're trying to render.

If unspecified, layout defaults to views/

Stash Variables

Instead of explicitly asking for passed parameters in your templates, as is the way plain ::Mojo is implemented, named arguments to template become scalar variables and positional arguments are available in array @pos:

    get '/foo' => sub { template '', 'Znet', :name<Zoffix> }

    # In views/
    <p>My name is <% $name ~ ' ' ~ @pos[0] %></p>

    # Results in:
    # <p>My name is Zoffix Znet</p>

This applies both to your layout templates and normal templates themselves.

Template Stash Setting

At the start of your template, you can use lines starting with %% followed by word-character key, followed by colon, followed by its value to set up stash keys. These will be available in both the layout and the template itself:

# in views/
%% layout: email
%% title: Foo Bar Baz
<p>Hello, World!</p>

# in views/layouts/
<title><%= $title %></title>
<%= $_content %>

The stash variables provided in the template can be overriden by providing those stash variables in the template call, thus your templates can specify default values.

template '', :title<SomeOtherTitle>;


Fork this module on GitHub:


To report bugs or request features, please use


Zoffix Znet (


You can use and distribute this module under the terms of the The Artistic License 2.0. See the LICENSE file included in this distribution for complete details.