Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Variable from Plugin visible in Templates

Quote Reply
Variable from Plugin visible in Templates
Hi,

if I use a variable in a Plugin, how can I make this variable visible in a template? (via <%variable%>)

JP
Quote Reply
Re: [petersenj] Variable from Plugin visible in Templates In reply to
How are you loading the template?
Quote Reply
Re: [Paul] Variable from Plugin visible in Templates In reply to
In Reply To:
How are you loading the template?

I don't know.

I was testing Plugins.
For example a plugin that hooks at do_logout. (where I tried the cookie-setting)

If I have a variable in the Plugin
my $testing = "testing";

How can I get this value to the template "login.html" that's showed after logout. Gossamer-Forum seems to load the template via
GForum::do_func('login');
from sub logout in User.pm

Thanks
Johannes
Quote Reply
Re: [jmar] Variable from Plugin visible in Templates In reply to
All the 'do_xxxx' POST hooks get the following arguments passed in:

$template, $tags, $opts

$template contains the name of the template to be displayed, $tags is a hashref with the template variables, and $opts are parsing options.

So, in your case, you would do something like
Code:
sub my_plugin_post_hook {
my ($template,$tags,$opts) = @_;

.... your code here ....

$tags->{test} = $testing;

.... more code maybe ....

return $template,$tags,$opts;
}
This will provide the tag <%test%> on the template, containing the value of $testing.

I hope this helps.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] Variable from Plugin visible in Templates In reply to
I think that's got a minor mistake...the first argument is always the name of the "do" parameter. So you'd need:

my (undef, $template,$tags,$opts) = @_;

Last edited by:

Paul: Apr 4, 2003, 12:29 AM
Quote Reply
Re: [Paul] Variable from Plugin visible in Templates In reply to
In Reply To:
I think that's got a minor mistake...the first argument is always the name of the "do" parameter.

Only for PRE do_* plugins - POST do_* plugins get the return value of the function, which is three variables indicated. Actually, sometimes the variables will be empty, which indicates that this do_whatever isn't parsing a template for one reason or another. The attachment download hooks are a good examples of things returning undef.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com

Last edited by:

Jagerman: Apr 4, 2003, 12:34 AM
Quote Reply
Re: [Jagerman] Variable from Plugin visible in Templates In reply to
Thanks to all! Helped a lot.

Regards
Johannes