i just took a look at the docs but i didn't get the clue. well, i know how
to do something with the context and the stasth, but i just don't know how
to specify the block, so when this block is called out from a template i
have a reference to the object to which the method belongs.

nearby the example from my prev. posting

package MyPackage;
use Template;
sub new {
   my $proto = shift;
   my %params = @_;
   my $class = ref($proto) || $proto;
   my $self = {};
   bless $self, $class;
   $self->{__myvar} = $params->{myvar};
   $self->{__template} = new Template({
      INCLUDE_PATH => '/mydir',
      BLOCKS => {
         'mysub1' => ??? # this should be something that points to mysub1
      }
   });
   return $self;
}


sub mysub1 {
   my $self = shift;
   my ($context) = @_;
   # do some stuff which needs information about the object of type
MyPackage
   # eg. access $self->{__myvar} 
}

the template i wish to process looks like (filename: test1.txt'):

...
Some stuff ...
[% INCLUDE mysub1 varfromtemplate = 50 %]
...
...


use MyPackage;

my $a = new MyPackage(myvar => '10');
my $b = new MyPackage(myvar => '20');

$a->{__template}->process('test1.txt');
$b->{__template}->process('test1.txt');



so when the template is processed and the predefined block 'mysub1' is
called i want to have a possibility to access the variables that i passed to
the constructor of $a and $b (in this case the variable 'myvar').

i hope i stated my problem more clearly now 


-----Urspr�ngliche Nachricht-----
Von: darren chamberlain [mailto:[EMAIL PROTECTED]]
Gesendet: Montag, 09. Dezember 2002 17:40
An: [EMAIL PROTECTED]
Betreff: Re: [Templates] BLOCKS directive points to method of an object
?


* Gernot Homma <[EMAIL PROTECTED]> [2002-12-09 10:31]:
> hello,
> 
> i have an object ($myobj) in which constructor i set up a
> template-object.  to this template-object i want to define some
> predefined blocks which are implemented as subs of $myobj. how can i
> do this.

Take a look at Template::Manual::Internals, specifcally the section
"Inside Looking Out"[0]; it might give you some hints.

(darren)

[0] <http://www.tt2.org/docs/plain/Manual/Internals.html#Inside_Looking_Out>

-- 
The Earth quakes and the heavens rattle; the beasts of nature flock
together and the nations of men flock apart; volcanoes usher up heat
while elsewhere water becomes ice and melts; and then on other days it
just rains.
    -- Principia Discordia

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.ourshack.com/mailman/listinfo/templates

_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.ourshack.com/mailman/listinfo/templates

Reply via email to