The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Statocles::Template - A template object to pass around

VERSION

version 0.062

DESCRIPTION

This is the template abstraction layer for Statocles.

ATTRIBUTES

content

The main template string. This will be generated by reading the file path by default.

path

The path to the file for this template. Optional.

theme

The theme this template was created from. Used for includes and other information.

METHODS

BUILDARGS

Set the default path to something useful for in-memory templates.

render

    my $html = $tmpl->render( %args )

Render this template, passing in %args. Each key in %args will be available as a scalar in the template.

coercion

    my $coerce = Statocles::Template->coercion;

    has template => (
        is => 'ro',
        isa => InstanceOf['Statocles::Template'],
        coerce => Statocles::Template->coercion,
    );

A class method to returns a coercion sub to convert strings into template objects.

TEMPLATE LANGUAGE

The default Statocles template language is Mojolicious's Embedded Perl template. Inside the template, every key of the %args passed to render() will be available as a simple scalar:

    # template.tmpl
    % for my $p ( @$pages ) {
    <%= $p->{content} %>
    % }

    my $tmpl = Statocles::Template->new( path => 'template.tmpl' );
    $tmpl->render(
        pages => [
            { content => 'foo' },
            { content => 'bar' },
        ]
    );

DEFAULT HELPERS

The following functions are available to the template by default.

content

    %= content
    <%= content %>

Add the main content of the template. This will be the HTML from the document or page.

include

    %= include 'path/file.html.ep'
    %= include 'path/file.markdown', var => 'value'

Include a file into this one. The file will be parsed as a template and given the same variables as the current template. Optionally, additional name-value pairs can be given to the included template. These additional template variables override any current variables.

Including markdown files does not automatically translate them into HTML. If you're in a page template or layout template, use the markdown helper to render the markdown into HTML.

markdown

    %= markdown $markdown_text
    %= markdown $app->{data}{description}
    %= markdown include 'path/include.markdown'

Render the given markdown text into HTML. This is useful for allowing users to write markdown in site data, and app data in the configuration file, or document data attributes in the document frontmatter.

Combining the markdown and include helpers allows for adding template directives to any included markdown file.

SEE ALSO

Statocles::Help::Theme
Statocles::Theme

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Doug Bell.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.