|
From: Chris W. <ch...@cw...> - 2001-12-17 12:48:30
|
On Mon, 2001-12-17 at 03:21, Tho...@be... wrote:
> Hi there.
>
> Some question about handling with templates:
> I want to insert a ticker in the base_main.tmpl. I created a package named
> "ticker" with 10 entries in th db for the content (ticker.ID0 -
> ticker.ID10).
>
> My question is, how do I include the pkg in the base_main ?
>
> I tried like this: [% INCLUDE $websitename::ticker %]
> and different combinations with the name.
>
> But nothings works. Is it possible at all?
The easiest way to do this is with a component. Here's how to set this
up -- names of classes, methods and templates are up to you :-)
1) In your 'ticker' package, create an entry in conf/action.perl for
your component. This is how OI knows how to connect your component call
with Perl code:
$action = {
ticker_embed => { class => 'OpenInteract::Handler::Ticker',
method => 'show_embedded' },
...
};
2) Create a method OpenInteract::Handler::Ticker->show_embeded:
sub show_embedded {
my ( $class, $params ) = @_;
my $R = OpenInteract::Request->instance;
my $ticker_entries = $R->ticker->fetch_group;
return $R->template->handler( {}, { ticker => $ticker_entries },
{ name => 'ticker::show_entries' } );
}
3) Create a template 'show_entries':
<p>Ticker Entries:<br>
[% FOREACH entry = ticker %]
[% entry.name %] --> [% entry.value %]<br>
[% END %]
4) Call the component:
[% OI.comp( 'ticker_embed' ) %]
You can pass parameters from the component call to the perl code also:
[% OI.comp( 'ticker_embed', num_entries = 5 ) %]
These parameters get put into the \%params argument passed to your
handler.
Hope this helps,
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|