Cyclone3 Skin

Module

From Cyclone3 Wiki

  • Extension: *.mdl
  • Location: _mdl
  • Caching: can be cached

Modules are the basic functional parts of the Cyclone3 framework. There are standard modules like an article view, article list, image view, file list, and there are specific modules, created solely for a single customer, or customized modules, changed according to client's needs.

Here is an example of how a module looks:

A header, containing unicode setting:

 #!/usr/bin/perl
 # USE UTF-8 !!!
 package Tomahawk::module;
 use open ':utf8', ':std';
 use encoding 'utf8';
 use utf8;
 use strict;

The main executable part start:

 sub execute
 {

Loading the passed variables hash:

   my %env=@_;

Loading a module template (optional, sometimes you don't need to output anything, just process some data and functions):

   Tomahawk::GetXSGN('-convertvars'=>1) || return undef;

Loading template localization (optional, not really useful for single-language pages):

   if ($Tomahawk::mdl_C{'-xlng_load'})
   {
     main::_log("using xlng transformation");
     Tomahawk::GetXLNG() || return undef; # retrieve language xml
     Tomahawk::XLNGtoXSGN(); # implement XLNG into XSGN
   }

Processing data, working with database/files/whatever ... closing the executable part by returning success:

   return 1;
 }

And finally - a signature, and file ending:

 our $authors="open\@comsultia.com"; 
 1;

That's it. Although you can use any template name you wish, before the returning line, the module should store the output in $XSGN{'TMP'}, as only this will be received by the system and processed out to the viewer.

modern type of module

Modern module is using caching variables, template toolkit and calling headers

#!/usr/bin/perl
# USE UTF-8 !!!
package Tomahawk::module;
use open ':utf8', ':std';
use encoding 'utf8';
use utf8;
use strict;
 
# dependencies
use App::020::_init;
 
sub execute
{
  my %env=@_;
  my %env_out; # return and cache this variables
 
  # default environment variables
  $env{'limit'}=10 unless $env{'limit'};
 
  # load Tpl and override environemnt variables
  Tomahawk::GetTpl('env'=>\%env) || return undef;
 
  ...
  # this call will be processed and cached
  push @{$env_out{'call'}{'H'}{'add_DOC_meta'}},
       {'property'=>'og:title','content'=>"Title"};
 
  # return true and all collected variables (will be cached)
  return 1,%env_out;
}