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

Custom Templates for a plugin

Quote Reply
Custom Templates for a plugin
Hi there Smile

I'm creating a plugin using my own templates and I am using GT::Template to parse it.
I know how to pass parameters to the templates that is being parsed, but I can only pass along those I created in the script file...
Is there a way I can use Template globals in the templates? And is there also a way I can send the user's profile/acount information? Like in the GLinks Templates?

Thank you Wink


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
Hi,

Theres 2 options:

1) Use Links::SiteHTML::display('template', { your stuff } );

2) Pass in stuff like this to GT::Template

%$USER, %$CFG

However, that won't work with globals (only the first suggestion will)

Hope that helps (I very rarely use GT::Template directly - I prefer Links::SiteHTML::display() as it puts all the "extra" stuff in for you :))

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Custom Templates for a plugin In reply to
Quote:
Use Links::SiteHTML::display('template', { your stuff } );

So I should use it just as you have it there, where 'template' would be the main template and 'your stuff' the "parameters"?

Quote:

Hope that helps (I very rarely use GT::Template directly - I prefer Links::SiteHTML::display() as it puts all the "extra" stuff in for you :))

That will make my life alot easier.

Thanks Andy Smile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
Hi,

Quote:
Use Links::SiteHTML::display('template', { your stuff } );

So I should use it just as you have it there, where 'template' would be the main template and 'your stuff' the "parameters"?

Yup.

Lets say the template you're using it mytest.html .. and you have a hashref of $link - then you would call with:

Code:
Links::SiteHTML::display('mytest', { %$link } );
..or if you're not passing along other tags - you could do:

Code:
Links::SiteHTML::display('mytest', $link );

(only any good if you don't wanna pass in stuff like my_tag => $value)

Hope that helps Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Custom Templates for a plugin In reply to
Code:
'syntax error at (eval 61) line 2, near "head>" syntax error at (eval 61) line 43, near ") {" syntax error at (eval 61) line 51, near "; }" '
hmmm Unsure

You dont perhaps know what this means


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
Not really - without seeing the code (PM it to me, if you don't wanna post it here :))

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Custom Templates for a plugin In reply to
nah... I'll chuck it in here...

Code:
use Links::SiteHTML;

sub parse {

my( $cgi,$objTpl, $tpl, $vars ) = @_;

# Don't complain if $vars was undef
$vars = {} if !( defined( $vars ) );
$vars->{'version'} = '1.0.0';
eval Links::SiteHTML::display($tpl, { %$vars } );
#eval $objTpl->parse_print( $tpl, { %$vars } );

if( $@ ) {

print "<h2>$0: error in parse_print(): '$@'</h2>";
return 0;
} else {
return 1;
}
}

There we go: $tpl contains "Results.html" and $vars contains the tags.
I used the eval to find out what is wrong... I think....
Without the evel keyword, the page just displays blank.


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
Ah, I see the mistake =)

You need to do:

print Links::SiteHTML::display($tpl, { %$vars } );

...otherwise it won't print out the output <G>

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Custom Templates for a plugin In reply to
Nice Smile Thanks Andy
It is working now


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
This is a bit of topic, but how do I hide the query string in the address bar?

ThanksSmile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
Hi,

Not sure what you mean? Normally - if its submitting from a form, you do it with a method="get" - so it knows to send the "form values" as a hidden. If set to method="post", it will do it like script.cgi?var=xcxc

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Custom Templates for a plugin In reply to
It is just to hide the query string from the address bar after the script generated the template....
Thanks Andy. Smile


Sacrifice is not about what you lose,
it is about what you gain in the process.
Quote Reply
Re: [EZFrag] Custom Templates for a plugin In reply to
Hi,

Mmm.. still not sure 100% what you're trying to do =)

If you wanna pass in some form values, without having it show in a URL - you can do something like:

$IN->param( 'Field_Name' => $value )

Not sure if thats what your asking though? Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Custom Templates for a plugin In reply to
Quote:
Normally - if its submitting from a form, you do it with a method="get" - so it knows to send the "form values" as a hidden. If set to method="post", it will do it like script.cgi?var=xcxc

No, it's the other way around.
Quote Reply
Re: [Wychwood] Custom Templates for a plugin In reply to
haha - can you tell the heats getting to me? Tongue (25 degree c in my room atm :/)