views:

54

answers:

4

Hi all,

I'm a relative newbie to web development. I know my HTML and CSS, and am getting involved with Ruby on Rails for some other projects, which has been daunting but very rewarding.

Basically I'm wondering if there's a language/backbone/program/solution to eliminate the copypasta trivialities of HTML, with some caveats. Currently my website is hosted on a school server and unfortunately can't use Rails. Being a newbie I also don't really know what other technologies are available to me (or even what those technologies might be). I'm essentially looking for a way to auto-insert all of my header/sidebar/footer/menu information, and when those need to be updated, the rest of the pages get updated. Right now, I have a sidebar that is a tree of all of the pages on my website. When I add a page, not only do I need to update the sidebar, I have to update it for every page in my domain. This is really inefficient and I'm wondering if there is a better way.

I imagine this is a pretty widespread problem, but searching Google turns up too many irrelevant links (design template websites, tutorials, etc.). I'd appreciate any help.

Oh, and I've heard of HAML as a way to render HTML; how would it be used in this situation?

+1  A: 

You use a template language.

Most often this will be processed on the server, but there are offline solutions which you run though a utility to generate complete HTML documents for uploading.

I'm rather fond of Template-Toolkit which I usually use server side with Catalyst but it also very usable before you involve a web server using the ttree utility.

David Dorward
+3  A: 

Server Side Includes.

Old as time. Supported in most hosting situations. Often forgotten in favour of hugely overcomplicated templating systems. SSI still has a place.

Oli
Thanks Oli, this seems like the simplest solution (my site is very small). I have a problem with relative paths, though. It's best described here: http://stackoverflow.com/questions/1016917/should-i-use-relative-path-for-pages-within-the-site-or-it-doesnt-matter (the templating issue). Is there an easy way around this? I've tried using "link rel="/yaddayaddayadda" but that doesn't seem to work locally, which is a bummer. Or is it best practice to have _all_ of the .html files in the root folder...? Mine are within subfolders. Edit:Maybe create multiple includes, one per subfolder depth?
Rockmaninoff
Not sure exactly what you're talking about. If you're doing `<link>` elements in the header (as your code suggests), you need to use `href` to point to the file. If you're talking about `<!--#include -->`, I suggest you use virtual paths. These are "root-relative" to your URL so ` <!--#include virtual="/inc/sidebar.html"-->` would always pull in the same file. The same applies for resource `<link>`s actually, root-relative will save you problems down the line.
Oli
In short, all your references to other files, be they a `<!--#include-->`, `<a>` or `<link>`, should probably use the whole root-relative path. There are exceptions where it's desirable not to do this but if you're having problems, now isn't one of those times.
Oli
Thanks again. I've set up XAMPP and now have SSI working, and now my root-relative paths are all set up. The problem was that I was just trying to access my pages from my local directory structure on my PC, and that didn't like SSI.
Rockmaninoff
+1  A: 

...........Wordpress?

mVChr
Downvote if you will, I stand by my answer based on his criteria.
mVChr
+1 - I wholeheartedly agree that recommending a CMS is the right thing to do. Be it Drupal (that's what I recommended), Joomla, EZpublish, Wordpress or other, it should give him the possibilities to overcome the difficulties he describes.
mingos
+1  A: 

I'd recommend Drupal. The tree structure of a menu is an inbuilt function and you basically can forget about it at all. And inserting whatever you want in specified areas (footer, header, whatever's defined in a template). It relies on PHP and MySQL - that stuff can be used on almost any server. And it has a moderate learning curve, so you should be able to start doing magic in little time.

mingos