Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

accessing enviromental variables from a template

Quote Reply
accessing enviromental variables from a template
Can/how would I access/set an environmental varialbe from a GF template ?

For example if I have a program
====
#!/usr/bin/perl

# tell gforum what to do
$Q_STRING="post=999;sb=post_latest_reply;so=ASC;forum_view=forum_view_expa\
nded;t=DRB;page=unread#unread";
$ENV{QUERY_STRING}=$Q_STRING;

# also set an environmental variable
$ENV{MY_VAR}='foo';

print `/var/www/gf/cgi-bin/gforum.cgi`;
====
How can I get the value of $ENV{MY_VAR} in the GF template ?

Thanks
Bob
Quote Reply
Re: [regert] accessing enviromental variables from a template In reply to
Create a global:

get_env => sub {
return $ENV{shift};
}

and then in the template put:

<%get_env('MY_VAR')%>

However, you can run gforum from the command line and the first argument will be treated as the query string:

perl /var/www/gf/cgi-bin/gforum.cgi 'post=999;sb=post_latest_reply;so=ASC;forum_view=forum_view_expa\
nded;t=DRB;page=unread'

and it will be like going to:

http://yourdomain/gf/cgi-bin/gforum.cgi?post=999;sb=post_latest_reply;so=ASC;forum_view=forum_view_expa\
nded;t=DRB;page=unread

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] accessing enviromental variables from a template In reply to
Alex,
Thanks for your help.

I tried to run gforum from command line with the query as an argument, but it didn't work.

Maybe I had a malformed query.

I have not had time to work on this the last several days. I'm hoping that as an environmental variable, the value will be passed on to child processes without my having to repeat it in each cgi query.

Bob
Quote Reply
Re: [regert] accessing enviromental variables from a template In reply to
Quote:
tried to run gforum from command line with the query as an argument, but it didn't work.

You should always include what the error was (doesn't work is never very helpful). =)

For instance, I can run from shell:[/quote][root@gossamer gforum]# ./gforum.cgi 'post=123'
Content-type: text/html
No-cache: 0


<html>
<head>
<title>Gossamer Forum: Products: DBMan: Customization: abbreviated list_all</title>
..[/quote]
which will gave me the same output as going to:

http://www.gossamer-threads.com/perl/gforum/gforum.cgi?post=123

Cheers,

Alex
--
Gossamer Threads Inc.