Menu

Patch to support <TMPL_VAR> ....</TMPL_VAR>

2002-03-12
2002-03-14
  • Emiliano Bruni

    Emiliano Bruni - 2002-03-12

    I find usefull, when developing web pages in a WYSIWYG environment, to show an example text for placeholder where HTML::Template replace dynamic text with TMPL_VAR tag.

    I create this patch to support a

    <TMPL_VAR ....>this is a placeholder text and here i can write whatever i want</TMPL_VAR>

    structure to visual formatting an placing dynamic text that HTML::Template then replace using TMPL_VAR tag.

    The patch also add a template file and a test step to check this new structure. Save the patch ad apply with "patch -p1 < nameofpatch.patch" before build the module.

    Hoping Tregar add this patch in the next release of HTML::Template.

    Best regards.

    ------------------------------------------------------------
    +      Dott. Bruni Emiliano - Graduated in Physics         +
    ------------------------------------------------------------
    +   Cisco Certificated Designer Associate                  +
    +   Software developer & Network Administrator             +
    +   Nick Handle: EB1346-RIPE  BE1484        ICQ: #16774468 +
    +   E-Mail: bruni@micso.it                                 +
    +   Web:    http://www.ebruni.it                           +
    +----------------------------------------------------------+

    ---- Cut here and save with HTML-Template-2.5-slash-var.patch filename ----

    --- /usr/src/HTML-Template-2.5/Template.pm      Sat Feb  2 00:01:37 2002
    +++ HTML-Template-2.5/Template.pm       Tue Mar 12 09:43:49 2002
    @@ -1723,6 +1723,16 @@
       $options->{vanguard_compatibility_mode} and
         $self->{template} =~ s/%([-\w\/\.+]+)%/<TMPL_VAR NAME=$1>/g;

    +  # handle the <TMPL_VAR>....</TMPL_VAR> structure
    +  $self->{template}   =~ s{
    +                        (<\s*                            # first <
    +                        [Tt][Mm][Pp][Ll]_[Vv][Aa][Rr]    # apply to TMPL_VAR tag only
    +                        .*?>)                            # this is HTML::Template tag  ($1)
    +                        ((.*?)                           # deleting all after here
    +                        <\s*\/                           # if there is the </TMPL_VAR> tag
    +                        [Tt][Mm][Pp][Ll]_[Vv][Aa][Rr]
    +                        \s*>)?}{$1}gmsx;
    +
       # now split up template on '<', leaving them in
       my @chunks = split(m/(?=<)/, $self->{template});

    --- /usr/src/HTML-Template-2.5/templates/simple-slash-var.tmpl  Thu Jan  1 01:00:00 1970
    +++ HTML-Template-2.5/templates/simple-slash-var.tmpl   Tue Mar 12 09:56:31 2002
    @@ -0,0 +1,9 @@
    +<HTML>
    +<HEAD>
    +<TITLE>
    +Simple Template with &lt;TMPL_VAR&gt;...&lt;/TMPL_VAR&gt; tag
    +</TITLE>
    +<BODY>
    +I am a <TMPL_VAR NAME="ADJECTIVE">this is a placeholder</TMPL_VAR> simple template.
    +</BODY>
    +</HTML>
    --- /usr/src/HTML-Template-2.5/test.pl  Tue Jan 29 05:03:46 2002
    +++ HTML-Template-2.5/test.pl   Tue Mar 12 09:55:01 2002
    @@ -3,7 +3,7 @@

    use strict;
    use Test;
    -BEGIN { plan tests => 55 };
    +BEGIN { plan tests => 56 };

    use HTML::Template;
    ok(1);
    @@ -20,6 +20,17 @@
    $template->param('ADJECTIVE', 'very');
    $output =  $template->output;
    ok($output !~ /ADJECTIVE/ and $template->param('ADJECTIVE') eq 'very');
    +
    +# test a simple template with <TMPL_VAR>...</TMPL_VAR> structure
    +$template = HTML::Template->new(
    +                                   path => 'templates',
    +                                   filename => 'simple-slash-var.tmpl',
    +                                   debug => 0
    +                                  );
    +
    +$template->param('ADJECTIVE', 'very');
    +$output =  $template->output;
    +ok($output !~ /ADJECTIVE/ and $output !~ /placeholder/ and $template->param('ADJECTIVE') eq 'very');

    # try something a bit larger

     
    • Emiliano Bruni

      Emiliano Bruni - 2002-03-14

      Don't use previous patch!!!

      the patch i posted for supporting <TMPL_VAR>...</TMPL_VAR> don't work well when mixing with standard TMPL_VAR.
      Moreover the regular expression used in old patch was called every time you call the "output" method and didn't used caching method implemented by H:T.

      Now i've released a good patch that works well when mixing <TMPL_VAR> standard tag and <TMPL_VAR>...</TMPL_VAR> tag. Moreover patch algoritm is called only when the template is loaded from file or stream (the same time is called _call_filters internal method that is in the new method and every time is necessary to include an external file) and so all caching method implementing in H:T works well for best performance.

      I saw no performance degreade using this patch also with long (long) template files.

      This patch is available here:

      http://www.ebruni.it/en/software/perl/cpan/html/template/patch_slashvar.htm

      Let me know if you find problems using it.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.