Closed Thread Icon

Topic awaiting preservation: A Template, a template! My Kingdom for a template! (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12706" title="Pages that link to Topic awaiting preservation: A Template, a template! My Kingdom for a template! (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: A Template, a template! My Kingdom for a template! <span class="small">(Page 1 of 1)</span>\

 
The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 05-01-2003 08:45

Ok, here is the deal. I made a site for a client over a year ago. There are now roughly 150+ pages in the site and all of them have the same graphic layout. Now they want to change the layout of the site, which will involve doing it on 150 different pages. Needless to say I did not originally design the site for scalability and I want to plan ahead this time.

So I got an idea, but I don't know if it can be done. I want to use a template for the design and have a Perl script plug in the text on each page. I was thinking that I could do the text for each page as a plain old text file and then call on the individual text file in the URL. For example, if I had a template named template.html and wanted to call on the template to plug in sales information I could use the URL www.whatever.com/cgi-bin/perlscripthere.cgi?template.html=sales, or something like that.

Can this be done? I know very little about Perl. Is there a place to get a hold of a script like this? Any help would be great!

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-01-2003 10:47

there is nothing perl can not do! Nothing!!

Anyhow, this is almost trivial... you'll probably use some %%place_holder%% (or ever more than one, think %%title%%) in your template, and have the perl script replace that.
I don't know exactly how to do it in perl, I'd have to dig up the manual, don't do much in it... so wait for example for petskull, he'll be able to help you.

ps: If the pages were very much identical, you might also be able to do an extended search/replace action to get the layout, or extract the text from the old one...

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 05-01-2003 14:37

There are tons of ways to do exactly what you want, with a variety of languages.

here's a few examples other than Perl -
http://www.gurusnetwork.com/tutorials/php/phptemplate/phptemplate.html
http://www.gurusnetwork.com/tutorials/php/phptemplate2/phptemplate2.html
http://www.gurusnetwork.com/tutorials/ssi/ssi1_intro.html
http://www.gurusnetwork.com/tutorials/javascript/jsadvmenu/jsadvmenu.html
http://www.gurusnetwork.com/tutorials/javascript/javascriptssi.html



Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 05-01-2003 15:05

What he said ^^^^^^^^^^^^^^^^^^^^^

Perl has a number of template modules that work in a similar way to the above:

HTML::Template http://search.cpan.org/author/SAMTREGAR/HTML-Template-2.6/

HTML::Template::JIT http://search.cpan.org/author/SAMTREGAR/HTML-Template-JIT-0.04/

HTML::Template::Expr http://search.cpan.org/author/SAMTREGAR/HTML-Template-Expr-0.04/

___________________
Emps

FAQs: Emperor

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 05-01-2003 17:27

And this is dealt with in the FAQ:

:FAQ: How do I make updating my site design easier?

___________________
Emps

FAQs: Emperor

Petskull
Maniac (V) Mad Scientist

From: 127 Halcyon Road, Marenia, Atlantis
Insane since: Aug 2000

posted posted 05-01-2003 17:43

you know what would be cooler?

you could modRewrite the url to /mytemplate.html and include a .cgi in the 'body' of that 'mytemplate.html'

this cgi would read the calling url (e.g. "/coolest/shit/in/the/world/index.html") and rewrite it (as "/coolest/shit/in/the/world/index.txt") to use as the source of the include

this is something I've often thought about doing but never actually done..

...or you could simply include, say, a prewritten nav menu and only need to change the file you're including (probably the simplest answer)

for example- you've got a header that's exactly the same on every page. Let's say it's a table.

<table><tr><td><img src="superlogo.jpg"></td></tr></table>

well, you could simply swap out that line with <!--#include file="www.cool.com/includes/head.html"--> and throw that code (the one written above) in "head.html"

when a user downloads the page, instead of getting <!--#include file="www.cool.com/includes/head.html"--> the get <table><tr><td><img src="superlogo.jpg"></td></tr></table>

.... I like to harness the power of this simplicity with the power of Perl by doing something like this-

<!--#include file="www.cool.com/cgi-bin/head.cgi"-->

... like this, I can include whatever the fuck I want in the page the user gets by using a little Perl magic..

If the Perl file says somthing like this-

#usr/bin/perl
print "Content-type: text/html\n\n";
print "<table><tr><td><img src="superlogo.jpg"></td></tr></table>"

-there you have your header, but now you can use Perl to fuck with it...

remember what I said about getting the calling url, that can be done with a variable called HTTP_REFERER

damn... I'm at work now... more on this later...


Code - CGI - links - DHTML - Javascript - Perl - programming - Magic - http://www.twistedport.com
ICQ: 67751342

Piper
Paranoid (IV) Inmate

From: California
Insane since: Jun 2000

posted posted 05-01-2003 22:14

HTML::Template would be a good solution here. Check the docs that Emps linked to. Following is a very basic sample script and a real generic template set:

File: page.cgi
<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
#!/usr/bin/perl -wT

use strict;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use HTML::Template;

my $in = new CGI();

# Grab the page you want to display or set a default (index.tmpl)
my $page = $in->param('page')

The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 05-02-2003 08:46

Thanks all. I think I am gonna go with the PHP solution at http://www.gurusnetwork.com/tutorials/php/phptemplate/phptemplate.html. It looks like the easiest solution for what I need. I may experiment with the others just to get a better idea of the different functionalities of each code.

I was also wondering how one would configure a search option with this template idea. A traditional search code would pull up the .html file rather than opening it through the template. Any thoughts?

Oh, I almost forgot! Would I have to use a redirect code to make the index.php replace index.html so that when the site is pulled up the PHP template is opened rather than the HTML file?



[This message has been edited by The Jackal (edited 05-02-2003).]

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 05-02-2003 13:19

Well, the basic concept that I use (and I don't recall if the GN tutorial goes the same way or not) is to have the file call the template rather than the template call the file...that way when a search engine finds the content, the template is automatically dragged along with it.

I use a header, and a footer, as two seperate files. Each content file calls the header and the footer.

There are plenty of ways to draw dynamic content into each content file as well.
{edit - for example, on a couple of different image gallery pages I have, I use one file as a base for all the galleries - the page calls the specific info for the specific gallery (from a DB in some cases, out of an array in others, and could just as easily check for a text file in a given folder and include that as well) via a variable passed in the URL like you mentioned above. This sets up the content area to handle the gallery setup, while the header and footer still handle the general page layout.}

And in most cases, index.php will be called as long as their is not an index.html file as well. If it deosn't, yo should be able to contact the server admin and they should be able to configure the server so that it does.





[This message has been edited by DL-44 (edited 05-02-2003).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 05-02-2003 16:14

The Jackal: See here for search information:

:FAQ: How do I get a free site search engine for my site?

I spent a long time looking for the right engine for me (one which spiders the site rather than going around opening various files which is unwise) and PhpDig was the one for me - its the one I currently recommend - simple to set up and powerful.

To make the index.php file you main one use:

code:
DirectoryIndex index.php default.php index.html default.html



in your .htaccess file.

___________________
Emps

FAQs: Emperor

JKMabry
Maniac (V) Inmate

From: out of a sleepy funk
Insane since: Aug 2000

posted posted 05-02-2003 22:38

I've recently done a site that does just these 2 things.

It uses a content file, say index.php, that calls a header, footer, and a leftnav include via php includes like so

code:
<?php include ("$DOCUMENT_ROOT/includes/header.php"); ?>
<?php include ("$DOCUMENT_ROOT/includes/left_navs/press_room.php"); ?>

<h1>Headline!</h1>

<p>content content content content content content content content content
content content content content content content content content content content
content content content content content content content content content content
content content content content </p>

<p>content content content content content content content content content
content content content content content content content content content content
content content content content content content content content content content
content content content content </p>

<?php include ("$DOCUMENT_ROOT/includes/footer.php"); ?>



I used DGS Search to do the searching.

Together they work beautifully, and quick to get up and going.

Jason

[edit] fixing line wrap

[This message has been edited by JKMabry (edited 05-03-2003).]

The Jackal
Paranoid (IV) Inmate

From: The Dark Side of the Moon
Insane since: Jun 2000

posted posted 05-03-2003 09:08

Thank you guys so much! I can honestly say that I have had a web design epiphany! The GN tutorials on PHP templates has totally altered the way I will design sites in the future and it has peaked my interest in learning more about PHP.

I decided to use my current search script and have the file call the template. This way I do not have to switch any more coding htan is needed. Thanks again!

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 05-03-2003 14:09

The Jackal: Glad to here you found them useful. Thats the beauty of those template tutorials - its always easier to learn this kind of thing by doing things you need to do and who doesn't need to make thir life easier with a little bit of code??

___________________
Emps

FAQs: Emperor

« BackwardsOnwards »

Show Forum Drop Down Menu