dTemplate

A simple yet powerful template handling logic with advanced features
Download

dTemplate Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Szabo Balazs
  • Publisher web site:
  • http://hacks.dlux.hu/drsync/

dTemplate Tags


dTemplate Description

A simple yet powerful template handling logic with advanced features dTemplate is a Perl module designed to be a fast, general-purpose, lightweight but easily extendible templating system.With this module, you can write template-parsing routines in the way the templates are structured logically: starting from outside to inside. Your code will be clear, well-structured and easy to understand. This logic can be attained using by inline subroutines as values of template variables. (Look at the example at the end of the document).SYNOPSIS use dTemplate; # definition $mail_template = dTemplate->new( file => "mail_tmpl.txt" ); $template = dTemplate->new( text => "< html >$BODY$< /html >" ), # parsing $mail = $mail_template->parse( FROM => { first_name => "Balazs", last_name => "Szabo", email => "dlux@dlux.hu" }, TO => "foo@bar.com", SUBJECT => $subject, BODY => sub { $email_type==3 ? $body_for_type_3 : $body_for_others }, SIGNATURE=> $signature_template->parse( KEY => "value" ) ); print "Please send this mail: $mail";where mail_tmpl.txt is: From : "$FROM.first_name$ $FROM.last_name$" To : $TO$ Subject : $SUBJECT$ Message body: $BODY$ $SIGNATURE$ ### Advanced feature: Styling # Style definition $style= { lang =>'hungarian', color=>'white' }; # Selector definition $html_template = dTemplate->new(choose => $style, 'hungarian+white' => dTemplate->new(file => "hun_white_template.html"), 'spanish' => dTemplate->new(file => "spanish.html"), 'black+hungarian' => dTemplate->new(file => "hun_black_template.html"), 'english' => dTemplate->new(file => "english_template.html"), 'empty' => "< html >This is a text, $BODY$ is NOT substituted!!!!"< /html >", # default: '' => dTemplate->new(text => "< html >$BODY$< /html >"), ); # Selector definition $body_template = dTemplate->new(choose => $style, 'hungarian' => dTemplate->new(file => "sziasztok_emberek.html"), 'spanish' => dTemplate->new(file => "adios_amigos.html"), # default: '' => dTemplate->new(file => "bye_bye.html"), ); print $html_template->parse(BODY => $body_template->parse()); # will print "sziasztok_emberek.html" in the # "hun_white_template.html" %$style = (); print $html_template->parse(BODY => $body_template->parse()); # will print "bye_bye.html" surrounded by "< html >" and "< /html >" tags. %$style = ( lang => 'english' ); print $html_template->parse(BODY => $body_template->parse()); # will print the "bye_bye.html" in of the "english_template.html" ### Advanced feature: Changing placeholder special characters: $dTemplate::START_DELIMITER = ''; # default: $ $dTemplate::VAR_PATH_SEP = '/'; # default: . $dTemplate::PRINTF_SEP = '$'; # default: %+ $dTemplate::ENCODER_SEP = '@'; # default: *+ $dTemplate::ENCODER_PARAM_START = '('; # default: / $dTemplate::ENCODER_PARAM_END = ')'; # default: # dTemplate 2.2 Compatibility: $template1 = define dTemplate "mail.txt"; $template2 = text dTemplate "This is the template text..."; $template3 = choose dTemplate \%hash, ...; Requirements: · Perl


dTemplate Related Software