Forum Moderators: open

Message Too Old, No Replies

Template-driven html page generation

Can anyone recommend software to do this?

         

Joal_Taylor

2:27 am on Apr 16, 2003 (gmt 0)

10+ Year Member



I have recently started development on a web site for a small amateur organisation with which I am involved. So far I've got a pretty satisfactory set of half-a-dozen or so pages. As you'd expect, there are a fair few similarities between them. They all have the same structure, the same masthead, and the same side menu, except that one entry in the side menu has a class="selected" attribute in order to highlight the menu entry approriate to the current page.

Having to make the same changes across all of the pages is already getting a little tiresome (and error-prone) and will only get more so.

What I would like to do is this. When I create a new page, I would like to just type up the new content and then start a process that generates the final page, including the mast and side menu (maybe even cuts out unnecessary whitespace to reduce filesize). It would also, of course, regenerate all of the other pages so that the new menu items appears in all of them. Similarly, if I want to make a change to the masthead (which will not happen very often at this stage, but may happen) then I would like to just change a template and hit the button. Once the page generation is complete, and all the pages have been checked out in various flavours of browsers, then I can dump it all onto the server.

Does anyone know of any software that can do this kind of thing? Simple file inclusion would be easy - the main feature I'm after is the ability to modify the markup based on the page being generated (i.e. adding class="selected" to the tag for the menu entry of the current page).

Either Windows or Linux based software would be fine. btw, I'm not using any fancy html editors to write up the pages - just vim. If any html editors do this kind of thing, I'd consider using one of them (I'd really prefer to stick with vim, though - I'm just so familiar with it).

Many thanks for your help.

DrDoc

3:08 am on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, there are... sort of.

First, let me tell you this - there are several programs that say they do this, which usually results in code crappier than if my Grandmother made it :)

On a more serious note, the closest you'll come is probably a program that lets you use a template for any new documents you create. I know Macromedia HomeSite (previously owned by Allaire) does this. And, personally, I'd prefer that over a program that applies a template afterwards.

Finally, Welcome [webmasterworld.com] to Webmaster World!

grahamstewart

3:12 am on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I usually take this a step further an generate the pages using php as the user requests them.

For example, you might create a php file that looks like this...

[pre][1]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title><? echo $title;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<link rel="stylesheet" type="text/css" media="all" href="/styles/default.css">
</head>
<body>
<div id="headingbar">
<h1><? echo $sectiontitle;?></h1>
</div>
<div id="content">
<h2 id="pagetitle"><? echo $pagetitle;?></h2>
[/1][/pre]

and call it header.php and then do likewise for the common footer code.

Then you don't need to re-type this code for every new page you create, instead you just do this..

[pre]
$title = 'Your Site';
$sectiontitle = 'Welcome';
$pagetitle = 'A generated page';
<?php include_once 'header.php';?>

<p>My content goes here</p>

<?php include_once 'footer.php';?>
[/pre]

..which is great because if you decide you want to change the header or footer html you only need to do it in one place and the whole site changes.

Joal_Taylor

4:15 am on Apr 16, 2003 (gmt 0)

10+ Year Member



Hi DrDoc,

Does HomePage allow you to create your own templates? And if you change the template, will that affect all that documents that use it? Also, would it be able to do the sidemenu thing I described? Thanks.

grahamstewart,

I currently know practically nothing about php (except for its existance and what I've just seen in your post) but I will look into it. Thanks for your help.

gph

4:22 am on Apr 16, 2003 (gmt 0)

10+ Year Member



MS FrontPage (I beleive version 2000 and up) has a thing called "Include Pages". Include pages are external html documents that are loaded into the page at the point you specify. Changes to include pages will change any page they are included in. Include pages are xbrowser and work offline (I'd love to know how they work :)

You can also create templates with FP although I don't know how. Maybe it can work for you by combining include pages and templates.

grahamstewart

5:19 am on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well rather than get bogged down in learning php, check to see if your host supports Server Side Includes (SSI).

They would let you do something similar to what I am describing and might be easier for you to learn (though they are a little less flexible).

Marcia

6:04 am on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem with Front Page includes (or borders) is that it then becomes impossible to touch those pages without FP without running into problems.

gingerbreadman

6:21 am on Apr 16, 2003 (gmt 0)

10+ Year Member



By far the best way to do this is using a combination of Dreamweaver templates, library items and CSS.

It will save you hours and you can do your sidemenu thing.

Library items and templates are linked assets: editing a library item or template updates all documents in which these assets have been applied.

Use library items and templates when you want to reuse specific content or design elements throughout a site or across multiple sites. Library items are intended for individual design elements, such as a site’s copyright information or a logo. Templates let you control a larger design area. A template author designs a page and defines which areas of the page can accept either design or content edits.

I used to do it in homesite, not with templates, but liberal use of the global replace function.

The other way, like someone else mentioned ,is to use SSI which is easy to get your head around but laborious to apply to hundreds or thousands of pages.

An alternative is to generate your own template and have a CMS creating the content. This could be done in anything from PHP to ASP.

MrSpeed

7:33 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I would go the server side includes route.
The problem may be highlighting the class="selected" for the navigation. Depending on what your doing with the CSS you may have to end up with placing the menu on each page instead of an include.

Something I have done in the past when I insisited on haveing the menu in an include is to call a javasvript function to detect the title of the page. I would then use a bunch of if/else statements and if I matched the title of the page I would set the background color of the navigation to the highlight color.

I'll try to post some code.

mack

7:38 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



You might want to concider using a "content management system"

They are great things for ease of editing. You will simply need to configure the package for your look and feel and build your content fromn there.

MrSpeed

7:44 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See if this could work for you.

Here is what a template would look like.


<html>
<head>
<title>My Site - Products</title>
<meta name="description" content="blah blah blah">
<meta name="keywords" content="blah, blah, blah">
<!--#include file="header.html" -->

Content Here

<!--#include file="footer.html" -->

</body>
</html>

And here is what the html inside the includes would look like rendered in the browser. You can alos link to external js and css files.


<head>
<title>My Site - Products</title>
<style type="text/css">
<!--

.Navlink1,.Navlink2,.Navlink3 {COLOR: #ffffff; TEXT-DECORATION: none; font-family: arial; font-size: 10pt; font-weight: bold;}
a:link.Navlink {color : #ffffff;}
a:visited.Navlink {color : #ffffff;}
a:active.Navlink {text-decoration: none;}
a:hover.Navlink {text-decoration: none;}

-->
</style>
<script language = "javascript">
<!--

function LmOver(elem, clr)
{
//alert(elem);
elem.style.backgroundColor = clr;
elem.children.tags('A')[0].style.color = "#ffffff";
elem.style.cursor = 'hand'}

function LmOut(elem, clr)
{elem.style.backgroundColor = clr;
elem.children.tags('A')[0].style.color = "#FFFFFF";}

function LmDown(elem, clr)
{elem.style.backgroundColor = clr;
elem.children.tags('A')[0].style.color = "#FFFFFF";}

function LmUp(path)
{location.href = path;}

function setcolor(){
strPage = document.title;
if (strPage.indexOf('home')>0){
document.all.nav1.style.backgroundColor = "#ff0000";
}
else if(strPage.indexOf('index')>0){
document.all.nav2.style.backgroundColor = "#ff0000";
}
else if(strPage.indexOf('Products')>0){
document.all.nav3.style.backgroundColor = "#ff0000";
}

}

//-->
</script>
</head>
<body onLoad="setcolor()">
<table border="0" cellspacing="1" cellpadding="1">
<tr><td id="nav1" onMouseover="LmOver(this, '#003366')" onMouseout="LmOut(this, '#336699')" onMouseDown="LmDown(this, '#003366')"
onMouseUp="LmUp('index.html')" bgcolor="#336699"><A HREF="index.html" Class="navlink1">&nbsp; Home</a></td>
<td id="nav2" onMouseover="LmOver(this, '#003366')" onMouseout="LmOut(this, '#336699')" onMouseDown="LmDown(this, '#003366')"
onMouseUp="LmUp('contact.html')" bgcolor="#336699"><A HREF="contact.html" Class="navlink2">&nbsp; Contact</a></td>
<td id="nav3" onMouseover="LmOver(this, '#003366')" onMouseout="LmOut(this, '#336699')" onMouseDown="LmDown(this, '#003366')"
onMouseUp="LmUp('products.html')" bgcolor="#336699"><A HREF="products.html" Class="navlink2">&nbsp; Products</a></td></tr>
</table>

</body>

DrDoc

9:52 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Unfortunately, HomeSite doesn't have a function that will change all pages afterward if you change the template. Sure, it lets you make your own customized templates, which can be applied to new documents, but that's about it.

I agree with the posts about SSI. Server Side Includes are wonderful when you want to include the same content on every page.

Thus, if you change the included document (or in this case only part of one) all pages will be instantly changed! The only bad part about this is that you can't really "preview" this behavior on your computer.

jimbeetle

10:06 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The 'include page' in Frontpage works okay, I've been using (stuck) with them for the past few years. It allows me to keep a constant header and footer and, for left and right nav or ad spaces I can have different 'includes' for different sections of the site.

It's kind of cluncky but it does work. The benefit is that the FP extensions save the pages as full html docs so there's no other server overhead involved.

Joel_Taylor, if the site is going to be fairly large you should look into Dreamweaver. Besides supporting templates it supports sub-templates so different sections can have their own characteristics. I played around with a trial copy when it was released but decided that the learning curve and converting sites was just too much at the time.

<added>Drawback to Frontpage is that you must rely on your server people keeping the Frontpage extensions in good working order. If not you can have major headaches such as a site being unusable for a month or so.</added>

Jim

sun818

10:15 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



There are several PC based programs that I've tested in the past that does what you want. The most idiot proof one I know of is Qixite (freeware). You can learn the whole program in 10 minutes.

Two others I know of is DBtoWEB (I use this) and WebMerge (have not used extensively). But these are more complicated and require a database to work off of. It may be more than you need.

Nick_W

10:19 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



>crappier than if my Grandmother made it

That's for sure!

If you're gonna do it, do it properly. [smarty.php.net]

You'll need to invest some time and effort initially but you'll never look back..

And welcome to WebmasterWorld ;)

Nick

grahamstewart

10:57 pm on Apr 16, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MrSpeed: I really hope thats not the header that you are using. Try adding a doctype and moving your css and javascript to external files. That should speed up the page loading. Then try validating your html.
Oh and ditch that mouseOver script - you can do that styling in CSS instead (see a:hover)

The problem may be highlighting the class="selected" for the navigation. Depending on what your doing with the CSS you may have to end up with placing the menu on each page instead of an include.

One way to handle this in a static manner is to set a different id for the body of each page. Then you can use this id to style the links. e.g. html like this..


<body id="homepage">
<div id="menu">
<a href="/index.html" id="linkhome">Home</a>
<a href="/pics.html" id="linkpics">Pics</a>
<a href="/sounds.html" id="linksounds">Sounds</a>
</div>
</body>

and CSS like this...


#menu a {
color: #0000ff;
background: transparent;
font-weight: bold;
}

#homepage #linkhome, #picspage #linkpics, #soundpage #linksounds {
color: #0000aa;
background: transparent;
font-weight: normal;
}

So normal menu links are bold and bright red, but the current link is duller red and normal. (Not very nice styling but you get the idea :))

gph

11:17 pm on Apr 16, 2003 (gmt 0)

10+ Year Member



jimbeetle I agree with you that FP include pages can be cluncky. The issue I've noticed is changes to included pages sometimes don't show locally. I think hidden files aren't always updated. A cluncky fix is to temporary rename the include page and let FP update linked pages.

Just to clarify, include pages don't use FP server extensions.

MrSpeed

12:20 am on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



MrSpeed: I really hope thats not the header that you are using. Try adding a doctype and moving your css and javascript to external files. That should speed up the page loading. Then try validating your html.

I just copied some proof of concept code I was working on for somebody and would do all those nice things before going to production.

grahamstewart - I'll have to try that code of yours.

jimbeetle

1:30 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Just to clarify, include pages don't use FP server extensions.

gph,

They sure do, or at least they are affected by them if they go bad. Had a huge problem last year with three sites almost unusable for the better part of a month. My very big, very muckety-muck host (no longer) refused to install the needed SP1 patches after upgrading to XP versions.

See MS KB Q298827 for NT [support.microsoft.com] or MS KB Q299360 for Unix [support.microsoft.com]

The extensions rewrite and update pages affected by changes to any included pages ("Processing web updates" message after publishing).

Jim

gph

9:26 pm on Apr 17, 2003 (gmt 0)

10+ Year Member



Then how do they work from floppy disk?

I've used them on more than 1 server that didn't support FP extensions. Specifically default space that came with cable service. They didn't support anything but a few premade CGI forms let alone FP extensions.

I can see where using extensions could cause problems but I'm 100% sure that include pages don't require them. It looks to me like staying away from FP extension enabled servers would be the answer.

jimbeetle

11:53 pm on Apr 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



gph,

I thought I qualified what I said:

They sure do, or at least they are affected by them if they go bad.

And you're quite right. From what I understand if your use FP on a server that doesn't support extensions you're basically FTPing the locally saved files up to the server, which then do have all the updated include pages in place.

When publishing to an extension-enabled server, say after you made a change to one include page, the publishing routine only sends the changed include page, all the other pages are updated on the server.

As for staying away from extension-enabled servers, why not, if you aren't using any of the features that do require them.

Jim

Joal_Taylor

5:39 am on Apr 18, 2003 (gmt 0)

10+ Year Member



grahamstewart,

Hey, that's brilliant. Wasn't the kind of solution I was expecting, but solves the stickiest part of the problem. Thanks!

gph

3:13 pm on Apr 18, 2003 (gmt 0)

10+ Year Member



Joal_Taylor, glad you've got a solution that suits you.

jimbeetle, I think we’ve been misunderstanding each other. I'm saying they don't use extensions and you're saying they can be affect by them. I didn't know include pages could be adversely affect by extensions, thanks for the info.

jimbeetle

4:42 pm on Apr 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hey gph, as above, turns out that we're both right on this point. Like much else in this wacky business sometimes there is no one, absolutely definitive answer.

If things can only be simple,

Jim

NeedScripts

8:33 pm on Apr 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have been using FP for long time and am positive that "include page" does not require ssi or even FP extension on the server.

Here is something you can try to prove it to yourself.

1) Create a test site/web offline and use the inlcude function. Now close FP and open up the file in any text editor and view the code, you will see that the content of the include page is already within that file (darn FP uses it comments everytime though.)

Does anyone knows how to not have those comments?

NeedScripts

jimbeetle

2:53 pm on Apr 19, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



NeedScripts,

You're absolutely right. As gph states above FP extensions are *not required* for include pages to work.

But, as I state above, if FP extensions are installed then the behaviour is different and funky extensions can impact the site, as noted in the two MS knowledge base articles I cited.

As for those comments <!--webbot bot="Include"...,etc> that's the way FP calls and checks the includes. As far as I know there's no way around this.

Jim