Francesco,

It seems to me that you have a large template file, and depending on the
context you want to display (or include) different sections.

    *   I think this could have already been done using TMPL_IF

    *   Could you have used TMPL_INCLUDE instead, to build pages from template
components?

My apologies if I've misunderstood you.

Cheers,
Chris
--
Chris Davies, Manheim Online
Tel. 0113 393-2004  Fax. 0870 444-0482.  Mobile 07778 199069


-----Original Message-----
From: Francesco Martelli - HalNet [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 13, 2001 8:56 AM
To: [EMAIL PROTECTED]
Subject: [htmltmpl] <tmpl_skip>


- hi all im new of this mailing list.
- i'm happy to see it's more populated than cvs server.
- SORRY for my english.

ok, i will try to explain WHY i decided to implement this new tag into
Template.pm and HOW.

WHY:

my work is building websites so i have to keep alive and updated many
projects.
its possible (as u know) only using a template system.
html::template is very good in my opinion (no hard code inside html, etc..),
but it have (for me it had) a problem.
try to imagine this situation: we have to build a big site with similar
pages: so we decide to write a general template (say layout.html) containing
the recurrent items (company logo, menu, banner, bottom link, etc) and some
other templates for building sections or single pages.
now with a db and perl we can generate all the pages putting all the
components inside our layout.html.
but...
we have to build a search page and so we need a template where we can put
our arrayref of search results.
i said a template, not a parsed one.
how can we build it?
we could copy and paste layout.html in another file and start writing
<tmpl_loop>, <tmpl_var> inside, but if the company change logo we have to
modify 2 file and so on.
so its a bad idea.
we must write a template that displays search results without the recurrent
items, only the body of our page.
a better way is to make all the work on the fly: we could make a db query,
build our arrayref,
put in our search results template, parse it, put the output in the layout
template, parse it, print the final output.
mmm... do we want to be so sadic towards our server?
i know its not really a problem for a server but consider that a lower
number of code lines means a lower number of error chances.
we have discovered the main way to solve this problem.
we must insert, in generation time, the search results template  inside of
the layout.html file avoiding that file (or a part of it) to be parsed.
simply we need a "skip parsing tag".
how can we do it? reading the following lines.

HOW:

line ~1700:------------------------------------------------

(?:
  (?:[Vv][Aa][Rr])
  | (?:[Ll][Oo][Oo][Pp])
  | (?:[Ii][Ff])
  | (?:[Ee][Ll][Ss][Ee])
  | (?:[Uu][Nn][Ll][Ee][Ss][Ss])
  | (?:[Ii][Nn][Cc][Ll][Uu][Dd][Ee])
  | (?:[Ss][Kk][Ii][Pp]) # << this line to find the tag
)

line ~1800: the essential code:------------------------------

# change this
if ($which eq 'TMPL_VAR') {
  ...

# to this
if ($which eq 'TMPL_SKIP') {
  $self->{_skip}++;
  $post=$chunk if $self->{_skip}>1;
}
elsif ($which eq '/TMPL_SKIP') {
  $self->{_skip}--;
  $post=$chunk if $self->{_skip}>0;
  die "oops" if $self->{_skip}<0;
}
elsif ($self->{_skip}) {$post=$chunk}
elsif ($which eq 'TMPL_VAR') {
  ...

and the complete one: ---------------------------------------------

# change this
if ($which eq 'TMPL_VAR') {

# to this
if ($which eq 'TMPL_SKIP') {
  $options->{debug} and print STDERR "### HTML::Template Debug ### $fname :
line $fcounter : start SKIP\n";
  $self->{_skip}++;
  $post=$chunk if $self->{_skip}>1;
}
elsif ($which eq '/TMPL_SKIP') {
  $options->{debug} and print STDERR "### HTML::Template Debug ### $fname :
line $fcounter : end SKIP\n";
  $self->{_skip}--;
  $post=$chunk if $self->{_skip}>0;
  die "HTML::Template->new() : found </TMPL_SKIP> with no matching
<TMPL_SKIP> at $fname : line $fcounter!" if $self->{_skip}<0;
}
elsif ($self->{_skip}){
 $options->{debug} and print STDERR "### HTML::Template Debug ### $fname :
line $fcounter : skipping\n";
 $post=$chunk;
}
elsif ($which eq 'TMPL_VAR') {
  ...

line ~2100:----------------------------------------------------------

scalar(@ifstack) and die "HTML::Template->new() : At least one <TMPL_IF>...
scalar(@loopstack) and die "HTML::Template->new() : At least one
<TMPL_LOOP>...
$self->{_skip} and die "HTML::Template->new() : At least one <TMPL_SKIP>...
# << check

thats all-------------------------------------------------------

in the forum sam treggar answered to make an add-on module.
my question: 10 lines justify building a module...?

thank for reading until here.
frapan


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to