[Templates] trying to leave HTML::Mason for TT2

Jonas Liljegren jonas@paranormal.se
Sat, 5 Aug 2000 09:17:50 +0200 (CEST)


On Fri, 4 Aug 2000, Perrin Harkins wrote:

> On 4 Aug 2000, Randal L. Schwartz wrote:
> 
> > And can we get the equivalent of inheritance?
> 
> I do this by varying the template include path on different requests.  
> That way I can always call "topbar.html" but I can override which file
> that is in certain areas of the site.

I don't like the solution of inserting a header and footer in the page.

The header and footer are one unit and should be looked at as a box with
variable content.


I have defined a typical box by embedding one table in another:

[%- BLOCK box_start %]
   [% DEFAULT border='black' %]
   [% DEFAULT bg='#AAAAFF' %]
<table border=0 cellpadding=0 cellspacing=0 bgcolor="$border"><tr><td>
<table border=3 cellpadding=10><tr><td bgcolor="$bg"><pre>
[%- END -%]

[%- BLOCK box_end -%]
</pre></table></table>
[% END -%]


This is used for reporting diffrent kinds of errors:

[% CATCH DBI %]
   [% INCLUDE box_start border='red' bg='#AAAAAA' %]
<h1>Database error</h1>
<pre>$e.info</pre>
   [% INCLUDE box_end %]
[% END -%]

[%- CATCH incomplete %]
   [% INCLUDE box_start bg='yellow' -%]
<h1>Form incomplete</h1>
<p>$e.info
   [%- INCLUDE box_end %]
[% END %]

[% CATCH template %]
   [% INCLUDE box_start %]
<h1>Template error</h1>
<p>$e.info
   [% INCLUDE box_end %]
[% END -%]

[%- CATCH action %]
   [% INCLUDE box_start border='red' %]
<h1>Action error</h1>
<p>$e.info
   [% INCLUDE box_end %]
[% END -%]


I would rather not have to include the top and bottom separatly like
this.  And I don't think that PRE_PROCESS and POST_PROCESS solves this.


Like Randals example, a website could have the hierarchy:

Site
  Section
    Box
      Content


Every page should be generated using the specific section template and the
specific box layout.  

With the header and footer approach the content would be surrounded like
the error messages above. But it wouldn't work to do that all the way:

[%
  INCLUDE site_start;
  INCLUDE section_start;
  INCLUDE box_start;
%]

My content

[% INCLUDE box_end %]

separator...

[% INCLUDE another_box_start %]

More content

[%
  INCLUDE another_box_end;
  INCLUDE section_end;
  INCLUDE site_end;
%]



The specific template included would be based on the include_path, by
first looking for those templates in the section template dir or something
like htat.


But I would rather have another solution.  With TT2, the content of a
block can be passed as a parameter to another box.  So you could specify
the specific blocks: (Havn't tested this)

[% content_1 = BLOCK %]
Some content
[% END %]

[% content_2 = BLOCK %]
More content
[% END %]

[% INCLUDE site
   section = 'example_section'
   content_1 = $content_1
   content_2 = $content_2
%]







Have any of you thought of any better way to handle this?

-- 
/ Jonas  -  http://jonas.liljegren.org/myself/en/index.html