Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Are Plugin options avail from template?

Quote Reply
Are Plugin options avail from template?

From a plugin I get plugin options like this
Code:
# grab the plugin settings...
my $opts = Links::Plugins->get_plugin_user_cfg('ZipCodeSearch');
my $units = $opts->{units};

Can I get a plugin user config option from a template?
Code:
Distance in <%Links::Plugins::get_plugin_user_cfg('ZipCodeSearch')%>

If not, can I set a tag via plugin so it is available in a template?

Thanks,
Chris

RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Are Plugin options avail from template? In reply to
To answer my own question...

I had to write a short sub routine and put it in my Plugin.pm file
Code:
sub units {
#--------------------------------------------------------------------------------
# Get the text for units from user config options for use in templates.
#

# grab the plugin settings...
my $opts = Links::Plugins->get_plugin_user_cfg('ZipCodeSearch');

# units is the visible text, i.e. ['Mile','Kilometer','Nautical-Mile']. See Install.pm file.
my $units = $opts->{units};

return $units;
}


I was then able to grab the config option from a template like this
Code:
<label for="distance" class="name">Distance in <%Plugins::ZipCodeSearch::units%>:</label>


To return more than one variable can I do this?
Code:
return (units => $units, unitcode => $unitcode);

Thanks
Chris
RGB World, Inc. - Software &amp; Web Development.
rgbworld.com
Quote Reply
Re: [rgbworld] Are Plugin options avail from template? In reply to
Well, Links::Plugins::get_plugin_user_cfg('ZipCodeSearch') returns a hash ref of your plugin's configuration variables, so yes you can call that and all your plugin's config key/values will be imported. However, you're not using it correctly, you should be doing:
Code:
<%Links::Plugins::get_plugin_user_cfg('ZipCodeSearch')%>
Distance in <%units%>
And for the sub, to return variables for GT::Template to use, return a hash ref (you're returning an array).

Adrian