App::ZofCMS::Plugin::FileList - ZofCMS plugin to display lists of files
In your Main Config file or ZofCMS template:
plugins => [ qw/FileList/ ], plug_file_list => { list => { list1 => 'pics', list2 => 'pics2', }, },
In your HTML::Template template:
<ul> <tmpl_loop name='list1'> <li><a href="/<tmpl_var escape='html' name='path'>"><tmpl_var name='name'></a></li> </tmpl_loop> </ul> <ul> <tmpl_loop name='list2'> <li><a href="/<tmpl_var escape='html' name='path'>"><tmpl_var name='name'></a></li> </tmpl_loop> </ul>
Module is a App::ZofCMS plugin which provides means to display lists of files.
This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template
plugins
plugins => [ qw/FileList/ ],
You would definitely want to add the plugin into the list of plugins to execute :)
plug_file_list
plug_file_list => { name => 0, re => qr/[.]jpg$/i, list => { list1 => 'pics', list2 => [ qw/pics2 pics3/ ], }, }, plug_file_list => { list => [ qw/pics pics2/ ], }, plug_file_list => { list => 'pics', },
You can specify the plug_file_list first-level key in either Main Config File or ZofCMS Template file. Specifying the same keys in both will lead to the ones set in ZofCMS Template take precedence.
The plug_file_list key takes a hashref as a value. Possible keys/values of that hashref are as follows:
list
plug_file_list => { list => { list1 => 'pics', list2 => [ qw/pics2 pics3/ ], }, }, plug_file_list => { list => [ qw/pics pics2/ ], }, plug_file_list => { list => 'pics', },
The list key specifies the directories in which to search for files. The value of that key can be either a hashref, arrayref or a scalar. If the value is not a hashref it will be converted into a hashref as follows:
plug_file_list => { list => 'pics', # a scalar }, # same as plug_file_list => { list => [ 'pics' ], # arrayref }, # same as # hashref with a key that has a scalar value plug_file_list => { list => { plug_file_list => 'pics', } }, # same as # hashref with a key that has an arrayref value plug_file_list => { list => { plug_file_list => [ 'pics' ], } },
The hashref assigned to list (or converted from other values) takes the following meaning: the keys of that hashref are the names of the keys in {t} ZofCMS Template special key and the values are the lists (arrayrefs) of directories in which to search for files. See SYNOPSIS section for some examples. Note that default {t} key would be plug_file_list as is shown in conversion examples above.
{t}
re
plug_file_list => { re => qr/[.]jpg$/i, list => 'pics', },
Optional. The re argument takes a regex as a value (qr//). If specified only the files that match the regex will be listed. By default is not specified.
qr//
name
plug_file_list => { name => 0, list => 'foo', },
Optional. Takes either true or false values, specifies whether or not to create the name <tmpl_var name=""> in the output. See HTML::Template TEMPLATES section below. Defaults to: 1 (*do* create)
<tmpl_var name="">
HTML::Template TEMPLATES
1
In HTML::Template templates you'd show the file lists in the following fashion:
<ul> <tmpl_loop name='plug_file_list'> <li><a href="/<tmpl_var escape='html' name='path'>"><tmpl_var name='name'></a></li> </tmpl_loop> </ul>
The name of the <tmpl_loop name=""> is what you specified (directly or indirectly) as keys in the list hashref (see above). Inside the loop there are two <tmpl_var name=""> that you can use:
<tmpl_loop name="">
<tmpl_var name='path'>
The <tmpl_var name='path'> will contain the path to the file, that is the directory you specified . '/' . file name.
<tmpl_var name='name'>
The <tmpl_var name='path'> (providing the name key in plug_file_list hashref is set to a true value) will contain just the filename of the file.
Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS
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
bug-App-ZofCMS at rt.cpan.org
Zoffix Znet <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/)
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.
LICENSE
To install App::ZofCMS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::ZofCMS
CPAN shell
perl -MCPAN -e shell install App::ZofCMS
For more information on module installation, please visit the detailed CPAN module installation guide.