On 1/4/06, Michael Peters <[EMAIL PROTECTED]> wrote:
> I'm trying to use the TT plugin in a new application but I'm not sure if it 
> will
> do what I want it to do. I'm using a WRAPPER in my config to give the site the
> same look without having to alter the individual templates themselves.
>
> Now most of the time I want this WRAPPER, but there are occassions when I 
> don't.
>  What I want to be able to do is pass some sort of flag to turn off this 
> option.
> Now, I don't think you can change TT config options on an existing object and
> the CAP::TT doesn't provide a way to have multiple TT_CONFIG options (or
> multiple TT objects).
>
> Is there a way to accomplish this? Or should I just ditch CAP::TT and handle 
> the
> interaction on my own?

I generally do this by having the wrapper template check for the
existance of a variable.

wrapper.tmpl:
-------------------------
[% UNLESS skip_wrapper %]
  header stuff
[% END %]
[% content %]
[% UNLESS skip_wrapper %]
  footer stuff
[% END %]
-------------------------

If you find that too ugly, then you can do it in two steps:

wrapper.tmpl:  (standard wrapper file)
-------------------------
header stuff
[% content %]
footer stuff
-------------------------

master_wrapper.tmpl:  (this one is actually configured in the TT object)
-------------------------
[% IF skip_wrapper %]
[% content %]
[% ELSE %]
[% WRAPPER wrapper.tmpl %][% content %][% END %]
[% END %]
-------------------------


Either way, your code can pass the 'skip_wrapper' parameter to the
template when it doesn't want the wrapper.  You can do this manually
in your runmode, or simplify it by doing it in a tt_preprocess method:

sub tt_pre_process {
  my ($self, $file, $vars) = @_;
  $vars->{skip_wrapper} = 1 if $self->get_current_runmode =~ /^popup_/;
  return;
}

Or you can even have your template itself decide to disable the wrapper:

popup.tmpl
--------------------
[% SET skip_wrapper = 1 %]
This template will not be wrapped
--------------------


Generally, I always have a static configuration for my TT object
(which means it is easy to retain the object across multiple requests
which is a huge performance saver).  The only exception is the
INCLUDE_PATH which has it's own method so it can be altered after the
TT object has been created.

Cheers,

Cees

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to