Forum Moderators: mack

Message Too Old, No Replies

Flexible templates using pure HTML/CSS?

a few questions from a relative newbie

         

Kuyler

1:00 pm on Nov 13, 2006 (gmt 0)

10+ Year Member



I'm slowly but surely progressing towards my first ever site launch and I'd appreciate some tips from more experienced webmasters on how to proceed.

At the moment, the site in question is going to be a (potentially large) content website, with no fancy databases or anything like that. To date, I've been purely hand coding in HTML with heavy use of CSS, and have been pleased with the overall look and feel.

This is all well and good, but the problem is that I foresee tremendous headaches if I decide to change the layout - even for something as comparatively minor as adding an additional box on the left panel. What are some realistic options apart from manually updating the pages?

- SSI. The problem with this is that it presumably makes it way harder to "test" web pages when offline or when they aren't published yet.

- DreamWeaver templates. My main gripe here is that DreamWeaver seems to handle CSS WYSIWYG functions pretty badly - i.e. I sometimes see inexplicable black boxes around perfectly well-defined CSS divs. Furthermore, I wouldn't want to get too dependent on Dreamweaver for linkages between template and instance pages, especially if the linkages are broken, which I've heard can easily happen?

- PHP etc. Again, isn't it such a pain to easily preview PHP files residing on your hard drive?

- A CMS system. Definitely not - I've had experience with several of them. Installation is often a pain, and I invariably find them lacking in flexibility (short of complicated customization programming which seems harder than coding from scratch).

What do you guys think? Does it sound a bit naive to try to tackle what could end up to be a fairly extensive site merely by handcoding in HTML/CSS? Any advice would be much appreciated!

jtara

7:56 pm on Nov 13, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



- SSI. The problem with this is that it presumably makes it way harder to "test" web pages when offline or when they aren't published yet.

Why not just install a test webserver locally? It's idea to have a Linux box, but Apache installs easily and runs well enough on Windows. You're not demanding a lot of it - just basic page serving and SSI.

Kuyler

6:53 am on Nov 14, 2006 (gmt 0)

10+ Year Member



Thanks for the reply.

I don't have a Linux box handy, but for instance if I installed Apache on my Windows XP laptop, would that already be sufficient to test offline? I presume I wouldn't need to be connected to the internet to use Apache to test local documents.

Also, I presume from your reply that using SSIs is a very popular way to have flexible templates among web developers? I was thinking along the lines of having one template document for my pages, and only a single DIV's worth of unique content for each individual page, e.g.:


[Include Stuff]
<DIV>
[all content for that page, including sub divs etc]
</DIV>

Is this a common approach? Thanks again! :)

jtara

5:11 pm on Nov 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An Apache install on your XP machine would be more than sufficient for your purposes.

I'd guess that MOST big commercial HTML authoring packages now include some sort of local webserver in the box to allow for local testing of at least includes, so it's a popular approach.

No, you don't have to expose your test site to the Internet to test. You will reference it as "localhost" in the browser bar.

The approach you are suggesting looks good. I would add an include at the bottom of each page as well, though. It's always a good idea for divs to appear in the order in which they should be read, even though CSS ran reposition them. This way, they will make sense if read in a non-CSS browser. Keep this in mind when orgainzing your pages internally as well.

Did you know that Apache has a way to automatically do an include at the beginning and end of every page? That way, you don't even have to remember to put the includes on your pages. Now, if I could remember how to do this... (I don't currently do this, as I serve dynamic pages.)

jtara

8:28 pm on Nov 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, now I remember why I've never done the automatic inclusion of headers/footers... You really need a bit more flexibility than that.

For maximum flexibility, it's best to have includes in both the title and body sections of your documents. Here's an example:

<HTML>
<HEAD>
<TITLE>All Your Examples Are Belong To Us!</TITLE>
<!--#include file="/sitemeta.inc"-->
</HEAD>
<BODY>
<!--include file="/siteheader.inc"-->
<div class=content>
<P>Blah, blah, blah</P>
</div>
<!--#include file="sitefooter.inc"-->
</BODY>
</HTML>

sitemeta.inc contains your site-wide meta tags, javascript, and CSS. (Or, probably references to further .inc files, themselves containing references to javascript and CSS files.)

siteheader.inc and sitefooter.inc don't necessarily contain literal headers and footers, but whatever you want to wrap your content in.

I do believe there is a module that will allow you to filter content and include files based on regular expressions. But it's not included in the Apache distribution.

So, there is still a way to do this without having to actually put the includes in each content file. (At worst, you could use mod_ext_filter and pipe through grep...)

Ahhhh... it is coming back.... I'm thinking of the Apache::Footer module used with mod_perl. Apache::Sandwich will put your content between a header and footer, but this won't insert metas, etc. A better solution is Apache::SimpleReplace, which inserts the content of your .html pages into a template.

But it's not so bad simply to have a simple starter file like the one above that you just use whenever you start a new page. Just give some thought to where you want to put the includes for maximum flexibility.

Kuyler

8:41 am on Nov 16, 2006 (gmt 0)

10+ Year Member



Thanks very much for your help - I'll install Apache and give all this a whirl!

le_gber

9:11 am on Nov 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



couple of additional suggestions:

I would use php or asp as a way of adding your includes to the pages, that way if you ever decide to change your site to a database driven app you will not need to worry about having to change all of your URL's.

Also for include files do not use the .inc extension because if anyone guesses the filename they will be able to 'see' the file code (which if it contains only your navigation is fine, but when it comes to db connections it is not). Use the same extension as the other pages and your include will be parsed and only the output will be visible.

jtara

8:08 pm on Nov 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



do not use the .inc extension because if anyone guesses the filename they will be able to 'see' the file code (which if it contains only your navigation is fine, but when it comes to db connections it is not

DANGER, WILL ROBINSON!

This doesn't solve the problem. Any file name you use is ultimately "guessable" with enough tries. (Of course, you could make the file names completely random.)

First, this is only an issue if you are using php, etc. You can't "make database connections" from SSI files. They are just HTML.

If you are including files from PHP code, do NOT put the included files in a web-accessible directory!

If you don't want people to be able to see your includes, here are two good choices, which apply either to SSI or PHP. (Or other inline languages, as well.)

- Put the included files in a seperate directory. Do not make that directory visible through the server. SSI (or the language you are using) will still be able to access the files, but users will not be able to fetch them.

- Make them all a certain extension, or include some common pattern in the file names and don't permit your webserver to serve files with that extension (or pattern).

Kuyler

12:39 pm on Nov 23, 2006 (gmt 0)

10+ Year Member



Again thanks for the help.

A few additional questions:

1. Is having all your files named as .shtml the most common approach? Are there any potential downsides to be wary of?

2. In order to get the includes to be parsed I had to make a number of changes to the httpd.conf file of the Apache installation. Do practically all web hosts allow editing of this config file?

3. Theoretically I've gotten it to "work" on my local machine except for the fact that I get a weird pair of characters appearing on the page before my include output. All my .inc file has is a paragraph tag and a single word, and what I get on the screen is:


ÿþ

Word

The same occurs if I for instance have a DIV tag and an image in the .inc file. Any idea what that's about? Thanks in advance!

Kuyler

8:42 am on Dec 9, 2006 (gmt 0)

10+ Year Member



Can anyone answer my last post from two weeks ago? I'm poised to start development but can't resolve those last issues. Thanks in advance! :)

encyclo

2:43 pm on Dec 9, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Kuyler, sorry your last question went so long without a reply. You can use .shtml with no problems, it is a common approach when using server-side includes.

For the problem with extra characters, it looks like you have an encoding problem - the characters resemble a Unicode byte-order mark. A related thread:

[webmasterworld.com...]

See also:

[webmasterworld.com...]

You may need to resave the files with windows-1252 encoding to remove the byte-order mark. What character encoding are you defining for your pages?

Kuyler

12:20 am on Dec 11, 2006 (gmt 0)

10+ Year Member



Thanks very much for your help! After checking those links you posted, I found out what the problem was - I had saved my .inc file in Notepad. When I re-saved it as a Text File in Wordpad (which is what I'd also done for the initial HTML document), everything displayed correctly.

But yeah, currently I'm just handcoding in Wordpad and saving the files as Text Files (of course with .shtml extensions), and the line I use right at the top is:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

Provided this current handcoding approach is fraught with danger, do you have any recommendations for a good free text editor and format in which to save the files to avoid headaches in the future?

Also, is it common practice when you start with a web hosting service to have to delve into the Apache config files and manually enable SSI? Thanks in advance!

encyclo

1:04 am on Dec 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you install a web server on your local machine, SSI may well not be enabled, but on most hosts it is usually enabled by default.

As for the doctype, it's not the best choice when authoring new pages. I would recommend starting with option 1 as given in the following thread:

  • FAQ: Choosing the best doctype for your site [webmasterworld.com]

    You should also be declaring your character encoding on each page. For more information, see:

  • Meta tags and more - from <head> to </head> [webmasterworld.com]

    For the text editor, anything with syntax hilighting is ideal. I'm a Linux user so I'm not up to date with text editor recommendations for Windows, but I have used EditPlus in the past (not sure it's free though). You should not use Wordpad or Notepad as they are not able to handle character encoding sufficiently well.

  •