Re: [Templates] Calling BLOCKS inside templates
[prev]
[thread]
[next]
[Date index for 2005/03/05]
Randal,
> But once loaded, it's cached in memory.
Sure. I'm not worried about the speed issue.
> [% PROCESS my_template.tt2 | null %]
>
> would even ensure that the non-block output didn't interfere.
That's not _exactly_ what I need, but I wonder if I could leverage that
somehow ...
> Buddy> But I need to do this from the code,
>
> as in $tt->process('bar') ?
Right. Only, it's actually $tt->process('my_template.tt2/bar') (which of
course only works when EXPOSE_BLOCKS is true). But I think I've failed to
explain my problem sufficiently. At the risk of being long-winded, let me try
again.
Let's say I have a web page. My web page is named "fred". The "fred" page is
divided into 4 squares: let's call them foo, bar, baz, and ... whatever comes
after baz. <g> All 4 of these squares relate to the same thing (i.e.
fredness). But they capture individual aspects of fredness that can be
operated on by the web sufer separately. Now, I use OpenThought (which is
basically just carefully controlled Javascript) to allow me to change each
square individually (e.g. in response to some user input) without having to
refresh the whole page. That's what I'm shooting for.
The implementation of this, so far, is a template called fred.tt2, which
contains BLOCKs named foo, bar, baz and whatever-that-last-one-is. Of course,
fred.tt2 contains some other stuff too: at the very least the containing table
which holds the separate squares. When I want to load the page the first
time, I process fred.tt2. When I want to refresh only foo based on some user
input, I process fred.tt2/foo. All is well with the world.
But let's further say that there's some common thing that _all_ the squares
have to do, perhaps display errors in a common format. So I make a new BLOCK
called display_error. Now, if I need to display an error when I first load
the page (i.e. while processing fred.tt2), that's all fine and well. But if I
need to display the error when refreshing the foo square (i.e. while
processing fred.tt2/foo), I have a problem. If the display_error BLOCK isn't
inside the foo BLOCK, I can't call it. If the display_error BLOCK _is_ inside
the foo BLOCK, I've solved it for foo, but I have the same problem for bar et
al. I could give display_error its own template--say, display_error.tt2--but
this is a slippery slope which leads to lots of lots of little templates and
my HTML designer complaining that she can never find anything. I could always
use [% PROCESS fred.tt2/display_error %] inside BLOCK foo and its pals, but
then I've encoded the name of the template into the code and every time I
rename a file, or move it into a different directory, I've got to hunt down a
million places to change (so far, this solution is probably the best of a bad
lot, unless anybody else has a better suggestion).
Hopefully that makes more sense.
-- Buddy
_______________________________________________
templates mailing list
templates@xxxxxxxxxxxxxxxx.xxx
http://lists.template-toolkit.org/mailman/listinfo/templates
 |
(message missing)
|