Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Templates and cgi parameters

Quote Reply
Templates and cgi parameters
This should be an easy one, but I'm having a problem figuring it out.

How do a get a cgi parameter into my template ?

If I use http:/mypath/gforum.cgi?view_forum#my_var=TEST

how do I get the value 'TEST" into the view_forum template

Thanks.

Bob
Quote Reply
Re: [regert] Templates and cgi parameters In reply to
This should work;

gforum.cgi?var=value

Then call it via <%var%> .. which would print "value".

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] Templates and cgi parameters In reply to
Andy,
Your help is appreciated. Documentation is kinda sparse.

I put the following in the forum_view.html template just after the include_logo.html line:

<h2>PLEASE NOTE: <%MY_VAR%></h2>

I then went to:

http://pathto/gforum.cgi?forum=9;MY_VAR=MESSAGE

but got an error message

PLEASE NOTE: Unknown Tag: 'MY_VAR'

Suggestions ?

Thanks.

Bob
Quote Reply
Re: [regert] Templates and cgi parameters In reply to
Mmm...afraid I can't help you much more. My area of expertise is really Links SQL....I assumed they used the same kinda template system in GForum, as they did in Links SQL, so that should have worked.

Sorry I can't be of more help Frown

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: [regert] Templates and cgi parameters In reply to
You could use a global.

At the top of your template add:

<%load_params%>

Then for the global use:

Code:
sub {
return $IN->get_hash;
}

Then you can use any parameter as a tag. Beware of any security implications though.
Quote Reply
Re: [Andy] Templates and cgi parameters In reply to
I do this on my site using a global. It's just in the template, not the URL. Under the logo I have 'Admin Note: '<%admin_note%> in the category template. Then I change the global variable in the admin panel. But this doesn't 'pull' any info from another page...in that case I believe you would have to use the URL, cookie or db.

Dave
Quote Reply
Re: [Paul] Templates and cgi parameters In reply to
Paul
Thanks for your help.

I'm not certain where the code section you proposed should go. Is it just part of the template ?

Bob
Quote Reply
Re: [regert] Templates and cgi parameters In reply to
The tag should go in your template. The global should go as a new global (Build > User Globals)....

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] Templates and cgi parameters In reply to
I wonder if this is another Forum vs Links difference (or I'm just blind)

When I go to Admin/Templates/Global Vars, there is no "Build' choice.

... later ...

AHHA I looked again and way down at bottom there's something called NEW. I'll try that


Thanks again
Quote Reply
Re: [Paul] Templates and cgi parameters In reply to
Hi Paul,
I tried the following
1. Added <%load_params%> to the template but got an error Unknown tag: load_params.

2. Set up a global named my_param with line
sub { return $IN->get_hash} and inserted the line
<%my_param%> in the template.

I was puzzled as to how to access values in my_param but by analogy to the section 'Gossamer Forum Developers Guide : Enhancing Gossamer Forum' I tried <%MY_VAR%> [the page was called via 'http://the_path/forum.cgi?forum=9;MY_VAR=TEST ]

3. When that didn't work, I created another global variable that looks like:
Code:
# This file is auto generated and contains a perl hash of
# your template globals for 'default' template set.
# Generated on: Fri Feb 21 01:08:49 2003
# vim: syn=perl

{
'drb_hash' =>"sub {
use GForum qw/:user :forum $IN $DB $CFG $USER $GUEST $SESSION/;
$MY_VAR=$IN->(MY_VAR);
return {my_var=>'$MY_VAR' ; }"
};
thinking the variable would be accessed via <%my_var%>
but I failed miserably with multiple errors.

Every other template system I've used has made obtaining cgi parameters a snap. I keep thinking that I must be missing something obvious.

Any more suggestions ?

Thanks
Bob
Quote Reply
Re: [regert] Templates and cgi parameters In reply to
If you're just looking for a single CGI variable (e.g. 'my_var'), then you would create a global called 'my_var'. The content would be:

sub { $IN->param('my_var') }

Then when you want to add the my_var content, simply put: <%my_var%> in the template. The template tag should be the same name as the global; the value between the (parenthese) in ->param('....') should be the CGI parameter.

Alternatively, if there are multiple variables that you need to access, I'd add a new global; call it 'param', perhaps. The content of that global would be:

sub { $IN->param(shift) }

(Note that there are no quotes around shift)

Now, in the template, to get the CGI input, use:

<%param(my_var)%>

Neither case allows raw HTML to be passed in; if you want that capability, change the globals' contents to be:

sub { \($IN->param('my_var')) }

and

sub { \($IN->param(shift)) }

respectively. As Paul mentioned, there is a minor security concern with allowing the HTML - someone could change the input to display any HTML they like on the page. They can't show it or cause anything malicious to other users, unless they paste a link somewhere that people decide to follow.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [Jagerman] Templates and cgi parameters In reply to
Jason,
Thanks, that worked.

I was using ';' instead of '&' to separate parameters because I thought that was how some of the queries generated by GForum looked. I guess ';' is used by GForum for other purposes.

Paul's suggestion was probably correct too.

Bob
Quote Reply
Re: [regert] Templates and cgi parameters In reply to
; is treated no differently than & - we chose to use it instead because it means we don't have to worry about HTML escaping & into &amp; for 100% valid HTML. So, you should be able to interchange ';' and '&' anywhere in the GForum and notice no difference - GForum itself doesn't have any idea whether you used ; or & to separate parameters.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com