Zoffix Znet > App-ZofCMS > App::ZofCMS::Plugin::ConfigToTemplate

Download:
App-ZofCMS-1.001004.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.001004   Source  

NAME ^

App::ZofCMS::Plugin::ConfigToTemplate - plugin to dynamically stuff Main Config File keys into ZofCMS Template

SYNOPSIS ^

In Main Config File:

    public_config => {
        name => 'test',
        value => 'plug_test',
    },

In ZofCMS Template:

    plugins => [
        { ConfigToTemplate => 2000 },
    ],

    plug_config_to_template => {
        key     => undef,
        cell    => 't',
    },

Now we can use `name` and `value` variables in HTML::Template template...

DESCRIPTION ^

The module is a plugin for App::ZofCMS that technically expands functionality of Main Config File's template_defaults special key.

Using this plugin you can dynamically (and more "on demand") stuff keys from Main Config File to ZofCMS Template hashref without messing around with other plugins and poking with ->conf method

This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

Main Config File and ZofCMS Template First Level Keys ^

plugins

    plugins => [
        { ConfigToTemplate => 2000 },
    ],

You need to include the plugin in the list of plugins to run.

plug_config_to_template

    # these are the default values
    plug_config_to_template => {
        cell         => 'd',
        key          => 'public_config',
        config_cell  => 'public_config',
        config_keys  => undef,
        noop         => 0,
    }

    plug_config_to_template => sub {
        my ( $t, $q, $config ) = @_;
        return {
            cell         => 'd',
            key          => 'public_config',
            config_cell  => 'public_config',
            config_keys  => undef,
            noop         => 0,
        };
    }

The plug_config_to_template must be present in order for the plugin to run. It takesa hashref or a subref as a value. If subref is specified, its return value will be assigned to plug_config_to_template as if it was already there. If sub returns an undef, then plugin will stop further processing. The @_ of the subref will contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and App::ZofCMS::Config object. Keys of this hashref can be set in either (or both) Main Config File and ZofCMS Template - they will be merged together if set in both files; if the same key is set in both files, the value set in ZofCMS Template will take precedence. All keys are optional, to run the plugins with all the defaults use an empty hashref. Possible keys/values are as follows:

cell

    cell => 'd',

Optional. Specifies the cell (first-level key) in ZofCMS Template hashref where to put config file data. Defaults to: d

key

    key => 'public_config',

    key => undef,

Optional. Specifies the key in the cell (i.e. the second-level key inside the first-level key) of where to put config file data. Can be set to undef in which case data will be stuffed right into the cell. Defaults to: public_config

config_cell

    config_cell  => 'public_config',

Optional. Specifies the cell (first-level key) in Main Config File from where to take the data. Note that config_cell must point to a hashref. Defaults to: public_config

config_keys

    config_keys  => undef,
    config_keys  => [
        qw/foo bar baz/,
    ],

Optional. Takes either undef or an arrayref. Specifies the keys in the cell (i.e. the second-level key inside the first-level key) in Main Config File from where to take the data. When set to an arrayref, the elements of the arrayref represent the names of the keys. When set to undef all keys will be taken. Note that config_cell must point to a hashref. Defaults to: undef

noop

    noop => 0,

Optional. Pneumonic: No Operation. Takes either true or false values. When set to a true value, the plugin will not run. Defaults to: 0

EXAMPLES ^

EXAMPLE 1

    Config File:
    plug_config_to_template => {}, # all defaults

    public_config => {
        name => 'test',
        value => 'plug_test',
    },


    Relevant dump of ZofCMS Template hashref:

    $VAR1 = {
        'd' => {
            'public_config' => {
                'value' => 'plug_test',
                'name' => 'test'
            }
        },
    };

EXAMPLE 2

    Config File:
    plug_config_to_template => {
        key     => undef,
        cell    => 't',
    },

    public_config => {
        name => 'test',
        value => 'plug_test',
    },


    Relevant dump of ZofCMS Template hashref:

    $VAR1 = {
        't' => {
            'value' => 'plug_test',
            'name' => 'test'
        }
    };

REPOSITORY ^

Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS

BUGS ^

To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues

If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org

AUTHOR ^

Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)

LICENSE ^

You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.

syntax highlighting: