Gossamer Forum
Home : General : Perl Programming :

Dynamic pages using templates?

Quote Reply
Dynamic pages using templates?
This should be an easy one for you folks, but it's stumped this perl/cgi novice.

Consider a songwriter's website with 50 lyrics pages, each containing a single song. Rather than building and maintaining these 50 near-identical pages, I'd like to be able to design a single template file with placeholders (e.g. <!!title> ) where the data fields should go.

A source file with some sort of delimited fields (e.g. new lines, blank lines, whatever) would contain the data (text/HTML), which would replace the placeholders in the template when a user requested a particular page.

I believe the template and the data would be read into the script, and a merged document would be written out. Problem is, I have very little knowledge of perl/cgi and do not know how to accomplish this feat.

If anyone could provide help and/or some sample code I'd be most grateful.
Quote Reply
Re: Dynamic pages using templates? In reply to
Hiya,

Well, what you want to do *is* possible, but it's kind of doing the long way round. All you really have to do is modify your html.pl to deliver each record as a page.

Carol (JPDeni) has courteously made a wee add-on available which lets you view a short and long display of records. The first gives you the search results, and each short record in the search results then links you to the full display for the record.

I think this would be the easiest way of doing it. I created one too, but Carol's is probably tidier! Smile

Here's Carol's add-on:

www.drizzle.com/~hall/dbmod/short.txt

And here's my version of it, which might give you an idea of how it can be used:

irishfineart.com/home/

Just click on "List" All or "Search" to view the short display, and follow one of the associated links to see the long display. In fact try the search function, I'm kinda proud of it! Smile

Hope this is what you're looking for,
adam
Quote Reply
Re: Dynamic pages using templates? In reply to
Adam -- thank you for your reply! Your site functions beautifully -- and I do like that search feature.

Forgive me -- I am but a perl newbie who's still grappling with the basic ideas, and I'm afraid Carol's add-on is way over my head, at least without an explanation of exactly what it does at each step. I don't expect you to spend your whole day providing this, but I thought I should provide more details regarding my needs just in case there's a simpler way (or example).

What I don't need, at least for the moment, is a search feature as complex as yours. Each link will refer to exactly one 'record,' so there's no need for abbreviated records to link to more complete pages... as if 'Cork Series,' 'Olde Dublin,' and so forth (on your site) linked to only one page each.

Your advice may still apply: "All you really have to do is modify your html.pl to deliver each record as a page." Sounds good -- now where do I find a straight-forward example of 'html.pl'? I'm starting at square one. I'm not even clear on how and where records should be stored.

http://www.bestweb.net/~bpress/mus/mus.html

If you scoot over to the above URL you'll find a Museum of Printing Presses in which each press thumbnail links to a press page. I'd like these pages to be created on-the-fly, so that updating the layout could be achieved far more efficiently than what is required at present (i.e. changing every single press page one by one).

Is there any hope for me?
Quote Reply
Re: Dynamic pages using templates? In reply to
 
Quote:
Your site functions beautifully -- and I do like that search feature.

Ha! Flattery'll get ya everywhere! Smile

Anyway, this line worries me:

Quote:
I'm starting at square one. I'm not even clear on how and where records should be stored.

I take this to mean you haven't installed dbMan yet? Well, there's no point in me explaining how you can do it before the script is up and running on the server. You can rest assured though that what you want to do is possible, so get dbMan downloaded and installed, add your records and we'll take it from there.

Cheers,
adam
Quote Reply
Re: Dynamic pages using templates? In reply to
Adam -- you're quite right. I wasn't even aware that dbMan was what I needed. So that's the ticket, huh? I'll get to work installing it right away -- might take me a little while.

I assume most of its features can be permanently disabled? There's so much more there than I need, such as user login and add/remove features.

One other lead I'll mention, before I go off to decipher the components of dbMan: I found a site that seems to have another simple flat-database script installed, but from the looks of things it functions very differently from dbMan. If you looked at it would you be able to understand how it functioned, or if its functionality would work for me?

http://voice.conncoll.edu

My thanks again for your valuable assistance.

ecn
Quote Reply
Re: Dynamic pages using templates? In reply to
ecn,

I presume you mean buildpage.cgi? Well, I guess I jumped the gun, I thought that you wanted add/remove/modify functionality (I had just come out of the dbMan forum, so I must've had it on the brain!). Well, what you want could be done a few ways, depending on what detail you would want in your pages. Server Side Includes is probably the simplest option, to generate header, footer and navigation bars. I don't know if you're familiar with SSI, so I'll explain. Using a simple tag like this:

<!--#include virtual="/path/to/includes/file.dat"-->

You can call the contents of that file into your page. So if you use the Includes across a number of pages, you only need to change that one file to change the contents across all those pages. An example of this is available here: iewebs.com/v3/index.html , and here's what the page looks like before the server operates on the Includes: iewebs.com/v3/index.htm . The two pages are exactly the same, but the server is set to parse the .html page and replace the Include tags with the content of the files. You'll have to check with your server admin to see if SSI is enabled on your server though.

Almost exactly same thing can be done with frames, it just depends on your needs. For example, a page using SSI would be indexed by the search engines, whereas framesets tend to confuse them.

buildpage.cgi works along the same lines as this, it just replicates the SSI calls with Perl subroutines, but with the cgi generated content you can have a little more freedom, using a flatfile database as well, or instead of, the replicated SSI calls. You have the added advantage of calling all your content from the one file, but you have the disadvantage that search engines tend not to index CGI generated pages.

Finally, it can be done in the same format as Links, which actually creates a HTML page from the flatfile database, but considering your application, this might be a little complicated.

So do you need the search engines to index this content? Does it matter if it's delivered by one file or is the main aim just to be able to modify parts of the pages across the board. If you think you need something like buildpage.cgi, tell me exactly what you need on those pages, i.e. what would be the same and what would be different, and I'll fire something together for you, since I led you astray first day. Smile

Cheers,
adam
Quote Reply
Re: Dynamic pages using templates? In reply to
Adam -- you have not led me astray in the least. Your last posting is *hugely* helpful. I've been trying to get at that information for weeks now, but no one I've spoken to has been able to explain those methods as clearly and succinctly as you just did.

I was having difficulty explaining my needs clearly, but now you understand exactly what they are. dbMan and Links are, indeed, far more sophisticated than I'll need; the SSI option solves one of my problems, and will simplify my life immediately. I tried out the include-tag and it works like a charm. It will be perfect for those header-footer situations, as you have already shown. (Can older browsers make sense of SSI elements as well as the latest ones?)

I can see, however, that the SSI method has its limits. Suppose a page (or really, a collection of similar pages) includes numerous spots where particular data would replace an include-tag. Is there a more efficient way to generate these pages than using a whole bunch of different include-tags referring to different data files?

I suppose what I'm saying is that it sounds as though buildpage.cgi would be the ultimate solution to my present needs, though obviously I don't know what it can do. I didn't even know such a script existed by that name until you suggested it (where can I find it?) ... would it do roughly what I outlined in my first posting here? I'm not too concerned about the search engine issue you raise, though I appreciate the warning.

Two examples of what I'd like to do -- keep in mind I have no idea how difficult it would be to accomplish these goals, and if the solution is beyond what buildpage.cgi can handle, it might be beyond what I can handle myself, as far as programming is concerned:

(1) Consider a set of pages: each is comprised of specific information within a standard layout. Here's an example: http://www.bestweb.net/~bpress/press/unclec.html . Here the specific pieces of data, which include a photo of a printing press and details about the press (plus the title of the document), are scattered within an HTML table layout. Could buildpage.cgi extract the data from a file and insert each piece into its correct position in the layout?

(2) A more complex, but related, problem: A thumbnail menu of these printing presses (see http://www.bestweb.net/~bpress/mus/mus.html) comprises several pages, each of which shows 9 presses in a table layout. Currently, if I add a new thumbnail -- say an "Adams" press -- to the list, I have to go through the menu pages and bump the last image on each page to the first position on the next, moving all of the images forward one cell. Could buildpage.cgi (or a similar script) spare me this tedium by automatically generating menu pages by looking at a data file and displaying the first 9 entries it finds? This way, I could add new press data to the data file, and new menu pages would automatically be displayed to the user.

If you can even get me started in solving these issues, Adam, I would be overwhelmingly in your debt. You've already been exceedingly generous with your time -- in so doing you've saved me heaps of time in the long run.

Much obliged,

ecn
Quote Reply
Re: Dynamic pages using templates? In reply to
 
Gor! You don't want much do you? Smile

Ok, well I go for the easiest one first. You don't need to worry about SSI and browsers, because the browser has nothing to do with it. To explain the process, the server is set to parse certain file types for Includes. So when the server gets a request for that file type, it parses the page and if it sees an SSI tag, it does the action required, which can be to include the contents of a file, display the date or time, or execute a cgi script, etc.. All this is done on the server side, so as far as the browser is concerned, this is a normal HTML page.

Next, SSI and it's limits. Well, as far as I know there's no limit to the number of Includes you can have on a page, unless you just get silly. And I don't think that having more than one on a page will be better or worse than having several. But it can get messy and complicated I guess. The real limitations are with the server overhead, the more pages you have the webserver parse the more load you're putting on it. That said, I run several client sites (and my own!) using almost entirely SSI or CGI generated content and it doesn't do me any harm. It's totally down to the webmaster, the traffic, the relationship with the server admin and plenty of other factors.

But onto the burning issue... I've had a closer look at your site and read what you want to do, and I think (without being insulting) that you're kinda stepping in over your head to be honest with you. Ok, a buildpage.cgi type thing is pretty much easy-peasy, but I don't really see the logic in creating one script to handle that, another to handle the thumbnail menu, and possibly another later on for the "types" menu. All that could be done with a hacked-up dbMan, using a database of the presses to produce the same results. Not only that, but you could administer your database through the web.

I'll try and throw something together for you tonight that would operate like buildpage.cgi (I would say it was something that the chap custom wrote), but I would have to sit back and have a good think about the second one with the thumbnails. Maybe you think about starting off a little smaller next time. Smile Seriously though, if that site is a breadwinner for you, or there's a timeline on it, maybe you would be better off paying someone to install a complete system for you.

Just a suggestion. Which reminds me, where should I send my bill? Smile

Cheers,
adam
Quote Reply
Re: Dynamic pages using templates? In reply to
Great response, Adam -- you got right to the crux of the matter: what I'm asking for may involve a serious script setup, and may be over my head. That's most important for me to know.

Thank you for looking over the letterpress site; now when you tell me that 'a hacked-up dbMan' would do the trick, I can begin to understand why you say so. The site is for a non-profit organization, and it's unpaid volunteer work -- so paying a professional is out of the question. I'm afraid that means you won't be receiving a check from me anytime soon. Wink

I'm still extremely curious about how buildpage.cgi works -- but wait a sec --

I just realized I've led *you* astray. I referred you to http://voice.conncoll.edu, but I meant to refer you here, instead: http://voice.conncoll.edu/archives/

So sorry! *That* should explain my above comment about not recognizing 'buildpage.cgi' -- I thought you were referring to some commonly-known script, like dbMan. But you were talking about a script on that site. Now I see. The Archives page at that location, where I meant to send you, includes 'section.cgi' and 'digest.cgi,' which may in fact be custom scripts similar to buildpage.cgi. But it was those, and not buildpage, that I meant to call to your attention. They looked like they did something simple enough.

I have taken enough of your time, haven't I? I hope you're not spending valuable hours concocting a script for this complete stranger. Though, that's really my final question. A buildpage.cgi or section.cgi script would, I suppose, be the middle ground between using simple SSIs and a more complex system such as dbMan.

It's been a pleasure talking with you, Adam -- I've really appreciated your sagacity. Smile

ecn
Quote Reply
Re: Dynamic pages using templates? In reply to
 
Sagacity? Is that anywhere near MegaCity1? Smile

I reckon we'll have to start a new thread if this goes on. Don't sweat it about taking my time though, if I didn't have it I wouldn't be here. It's as much a learning experience for me as it is for you, but as I've mentioned before on this board, I don't like just creating stuff for people, I prefer to let them create it themselves and help them when they come across problems.

Anyway, those scripts you pointed me to operate in much the same way as buildpage.cgi, so that has no real bearing on the situation. I started throwing something together for you last night, but I still reckon you should install dbMan on your server, if only to make it easier for you to create and administer the whole setup.

The thing I'm creating can work with the data file you create with dbMan and as you get more comfortable with dbMan you could have the whole thing control your site, in much the same way I use it on the site I showed you before. This way you (eventually) get exactly what you want, and you learn a bit in the process.

You will need to decide what route you want to go. How quickly do you want to do this? If you're in no hurry, take your time and go the dbMan way. Anyway, either way you'll need to create a data file, in this format:

id|name|longname|inventor|manufacturer|chase|type

Just add or remove whatever you require. id will be a numerical id for the record (might make certain functions easier later), name will be a short name for the record (say adana or caxton), to make it easier to access the record with a nice short url. longname will be the proper name for the press and the rest can be what you want. If you have empty fields, don't just skip them, leave them empty, like this:

4|alert|Alert Press&#0124; &#0124;Gorham & Co.&#0124; &#0124;Platen jobber

You don't need to store your image names in the data file, the easiest way to get the images is to copy them and store them in another directory, renaming them to the value of name (i.e. alert.jpg). This way, you have one less field in your database to worry about, although you can have the field with the image URL if you wish. With the content, you can do it two ways. You can do it in the same way as the images, or you can have the html in your database, although the source of your html pages might look a little manky. I do it in the same way as the image files, but I haven't tried it the other way. I'll have to ask JPDeni about that.

So my suggestion to you is to get dbMan, configure it with whatever fields you want (Remember to think to the future. Might you want to add other fields later? It doesn't matter if some of the remain blank remember) and install it on your webserver. Then start adding your records and when you get stuck come back to this site, pop into either the dbMan installation or discussion forums and we can get you onto the next step.

Cheers,
adam
Quote Reply
Re: Dynamic pages using templates? In reply to
I like your teaching style, Adam. I learn by working my way *out* of things; I go backwards rather than starting at the beginning. Learned HTML, like many people, by examining other people's finished code and figuring out what each line does. I continue to study graphic design by scrutinizing others' good work. One of the reasons I'm eager to see what you come up with for 'buildpage.cgi' is that seeing the completed code would help me make sense of the language, and in leaps and bounds I'll bet. What little I already know about perl I learned by generously altering someone else's generic message board script to meet my own needs. I'm sure this is hardly unusual.

One question and then I'll go off to look closely at dbMan. Regarding the data file you describe: will this file include the long descriptive paragraphs relating to each press? Or is it simply meant for the basic press details, those that might appear in a listing of presses (such as the View by Types page)? From your example I assume the paragraphs of text come into play later, that they belong to the end destination of a 'search,' i.e. a single record. So the record body-text is not included in the data file, correct?

Okay -- one final concern: while perusing the site you referenced earlier, irishfineart.com, I found myself timed-out after a brief period of idle time. Trying to select a page, I was shown instead a screen on which I was asked to login with name and password. I didn't have to do that when I first arrived. Is this supposed to happen? Can the login (and add/remove) features of dbMan be easily disabled so that these login screens never show up, or does disabling them require hacking beyond what I could ever hope to do myself?

Thank you, again, Adam. Still dying to see your buildpage.cgi-type script if it's something you've already done. If I'm capable of taking the plunge into dbMan, I'll certainly be seeing you around these forums again.

ecn
Quote Reply
Re: Dynamic pages using templates? In reply to
ecn,

I'll try and keep this short, this thread is getting out of hand.

Ok, first off, I reckon that's how most people learned Perl, HTML and graphic design. I'm not big on educational books, I find I start dozing off quite easily. I reckon the Internet is as good a learning tool as any, so that's how I do it. If I find I'm referencing something very often, I save it as HTML and add it into my /docs directory locally, so it's nice and handy for next time. I suppose it depends on each persons way of handling it. I have books about HTML and Perl, I just can't be bothered with them, except for when I'm in a corner.

Ok, your data file doesn't need to contain the HTML/text describing the press. After a little "consultation" I reckon the easiest route to go is to take that text/html out of the full pages and save them as $name.htm and we'll simulate an Include with it.

And the bug you mentioned on irishfineart.com is just that, a bug. The problem comes when you follow a link from a print that's a collection or part of one, and the link reference is wrong, so the script tries to authenticate the user. I'm starting work on a categorised version of dbMan for that site shortly, so I couldn't be bothered fixing it.

You can remove the authentication features of dbMan, but I don't think that you really want to let regular web users play with your database do you? So you just set it up to allow a default user view it, and only administrators can add/modify/delete. You'll see all that when you set it up on your server.

Anyway,I can't complete something like buildpge.cgi until you comeup with a database definition for me. Try using Alex's Definition creator at gossamer-threads.com/scripts/dbman/build.cgi , it might make things a little easier for you.

adam
Quote Reply
Re: Dynamic pages using templates? In reply to
So what did you gents come up with? Come on fill us in so we can use that nice buildpage.cgi script you came up with. Sounds like something I could use on a project I am currently working on.

------------------
Wil Hatfield
HVHM
Quote Reply
Re: Dynamic pages using templates? In reply to
Wil,

The build script was written by Gossamer-Threads to facilate the creation of the default.cfg file for the DBMAN script. But there is a better configurating script called CONFIGURATOR at the following web site:


Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Dynamic pages using templates? In reply to
Elliot,

I guess you and I got two completely different ideas from the above thread. To my knowledge it was about using a buildpage.cgi to create static pages from DBMan sort of link good old Links does.

If you have any information regarding this topic it would certainly be appreciated.



------------------
Wil Hatfield
HVHM
Quote Reply
Re: Dynamic pages using templates? In reply to
Nope...I was clarifying that the build.cgi was used for...I would recommend contacting dahamsta to see what he has done with the script.

Wink

regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Dynamic pages using templates? In reply to
Unfortunately dahamsta has no direct contact details. My only means of contact is through the forum here. Oh well, just means extra time in front of that ole 'drawing board'.

Thanks for your help none the less. TTYL

------------------
Wil Hatfield
HVHM