The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Statocles::Theme - Templates, headers, footers, and navigation

VERSION

version 0.098

SYNOPSIS

# Template directory layout
/theme/site/layout.html.ep
/theme/site/include/layout.html.ep
/theme/blog/index.html.ep
/theme/blog/post.html.ep

my $theme      = Statocles::Theme->new( store => '/theme' );
my $layout     = $theme->template( qw( site include layout.html ) );
my $blog_index = $theme->template( blog => 'index.html' );
my $blog_post  = $theme->template( 'blog/post.html' );

# Clear out cached templates and includes
$theme->clear;

DESCRIPTION

A Theme contains all the templates that applications need. This class handles finding and parsing files into template objects.

When the "store" is read, the templates inside are organized based on their name and their parent directory.

ATTRIBUTES

url_root

The root URL for this application. Defaults to /theme.

store

The source store for this theme.

If the path begins with ::, will pull one of the Statocles default themes from the Statocles share directory.

include_stores

An array of stores to look for includes. The "store" is added at the end of this list.

tag_start

String that indicates the start of a template tag. Defaults to <%.

tag_end

String that indicates the end of a template tag. Defaults to %>.

line_start

String that indicates the start of a line of template code. Defaults to %.

expression_mark

String that indicates an expression to be evaluated and inserted into the template. Defaults to =.

escape_mark

String that escapes the template directives. Defaults to %.

comment_mark

String that indicates a comment. Defaults to #.

capture_start

Keyword that starts capturing string. Defaults to begin.

capture_end

Keyword that ends capturing string. Defaults to end.

trim_mark

String that indicates that whitespace should be trimmed. Defaults to =.

_templates

The cached template objects for this theme.

_includes

The cached template objects for the includes.

METHODS

BUILDARGS

Handle the path :: share theme.

read

my $tmpl = $theme->read( $path )

Read the template for the given path and create the template object.

build_template

my $tmpl = $theme->build_template( $path, $content  )

Build a new Statocles::Template object with the given path and content.

template

my $tmpl = $theme->template( $path )
my $tmpl = $theme->template( @path_parts )

Get the template at the given path, or with the given path_parts.

include

my $tmpl = $theme->include( $path );
my $tmpl = $theme->include( @path_parts );

Get the desired template to include based on the given path or path_parts. Looks through all the include_stores before looking in the main store.

helper

$theme->helper( $name, $sub );

Register a helper on this theme. Helpers are functions that are added to the template to allow for additional features. Helpers are usually added by Statocles plugins.

There are a default set of helpers available to all templates which cannot be overridden by this method.

clear

$theme->clear;

Clear out the cached templates and includes. Used by the daemon when it detects a change to the theme files.

pages

Get the extra, non-template files to deploy with the rest of the site, like CSS, JavaScript, and images.

Templates, files that end in .ep, will not be deployed with the rest of the site.

SEE ALSO

Statocles::Help::Theme
Statocles::Template

AUTHOR

Doug Bell <preaction@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 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.