Gossamer Forum
Home : Gossamer Threads Inc. : Discussion :

Using GT template engine outside GT scripts

Quote Reply
Using GT template engine outside GT scripts
Good Morning ...

The specific context for this question is DBManSQL, but as all GT scripts use the same template engine I am posting here -- it could apply equally to any set of data generated by a GT script (or from any other source) and might be useful to anyone who has a licence for any GT product that uses GT::Template.

This is what we would like to do ...

* Privileged users edit and maintain a database by logging into editors.ourdomain.org
* A cron job (run every 24 hours) builds static pages (one page per record) for browsing by normal users in www.ourdomain.org. Although the concept is similar to generating LSQL pages using cron, this build does not, and never will, require a CGI interface.

The simplest way (for us, as inexperienced Perlists) to build the static pages is to use the DBI and HTML::Template modules. We have a scheme which seems to work, but as we already have more than one copy of the GT template engine on the server, we would prefer to use it (also we think it is probably better than HTML::Template).

The questions:
1. How to use GT::Template in this way?
2. How can we access templates which have been developed and compiled in the regular DBManSQL/LSQL environments?
3. Has anyone done anything like this already?


Related GT thread: http://www.gossamer-threads.com/...orum.cgi?post=232182
URL for HTML::Template is http://html-template.sourceforge.net/
Quote Reply
Re: [YoYoYoYo] Using GT template engine outside GT scripts In reply to
Hi,

The syntax for GT::Template is really straightforward:

my $output = GT::Template->parse('template.html',
{ your template vars },
{ your template opts }
);

So for example your code might look something like:

while (my $row = $sth->fetchrow_hashref) {
open (STATIC, "> /path/to/some/static/page/$row->{ID}.html");
print STATIC GT::Template->parse('yourtemplate.html', $row);
close STATIC;
}

for more info on the options you can pass in, see the docs in our Links SQL demo at:

http://gossamer-threads.com/...ic=/GT/Template.html

(Username: admin Password: admin).

Cheers,

Alex
--
Gossamer Threads Inc.