Re: [Templates] object-oriented templates, inheritance, references to blocks : HOWT O ?
[prev]
[thread]
[next]
[Date index for 2004/04/27]
>>>>> "Dami" == Dami Laurent (PJ) <laurent.dami@xxxxxxx.xx.xx> writes:
Dami> I have a collection of templates which is likely to grow, and where
Dami> some components are shared, but the problem is that reuse is
Dami> context-dependent : in some cases a standard component can be
Dami> directly grabbed from the library ; in some cases it needs
Dami> a couple of local redesign adjustments.
Dami> It seems that plain inclusion of block components does not fit here,
Dami> so I'm trying to design the template collection in an object-oriented
Dami> way. The goal would be to be able to "subclass" a template and
Dami> overload some of its components.
You're probably looking for "views", which are something like
objects with inheritance.
I originally started the design of www.stonehenge.com with views, but
then later abandoned it. I still have a hierarchy for the styles of
my pages, but I use hooks and forward setting, rather than
inheritance, to get my variations.
The WRAPPER template uses META information in the page to PROCESS a
particular style, which can use variables set while gathering the
"content" to modify behavior, and can in turn process progressively
more generic styles. The WRAPPER looks like:
[% PROCESS "style/${template.style or 'default'}" %]
which looks at content and does the right thing. Each specific style
sets variables and processes the more generic style, which eventually
looks at "content" for the core of the page. The "inheritance" comes
from having each outer layer use DEFAULT or concatenate to the
style-type variables, so that inner styles can enhance or override
outer styles. I can also provide hooks, so if "top_bar_extra" is
defined, I create a two row table for the top-bar and insert the extra
data into the second row, instead of just the normal one row table.
Then any inner style can set top_bar_extra, and the hook is made.
I got the idea from Emacs Lisp, which doesn't have inheritance, but
makes do with hooks and layers.
It's mostly flexible, although I sometimes end up refactoring quite a
bit when I forgot to think about how I wanted to be flexible. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@xxxxxxxxxx.xxx> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
 |
Re: [Templates] object-oriented templates, inheritance, references to blocks : HOWT O ?
merlyn (Randal L. Schwartz) 17:05 on 27 Apr 2004
|