

Ask News.YC: Is hand-coded html an outdated and silly way to operate a site? - bmaier

It seems like everyone these days is using some sort of CMS.  Is there any reason to code the pages by hand anymore for a frequently updated site?  One of the few upsides I can see is the speedier load time of non-cms sites because of the lack of need for a database interaction but other than that I can't think of much else.  <p>Anyone out there not using some sort of CMS for a site of reasonable complexity?
======
tlrobinson
For really simple sites that don't need a full blown database backed CMS I
just use simple PHP includes like the following:

    
    
        <?php
            $title = "Whatever";
            include("header.php");
            include("content.txt"); // or just include the content inline
            include("footer.php");
        ?>
    

Then header.php is just:

    
    
        <html>
        <head>
            <title>My Site - <?php echo $title; ?></title>
            <!-- other header stuff like css, scripts, etc -->
        </head>
        <body>
            <div id="content">
    

and footer.php is just:

    
    
            </div>
            <!-- other footer stuff like Google Analytics, etc -->
         </body>
         </html>
    

If you want to get a little fancier you can set up a URL rewriting (like
Apache's mod_rewrite) to internally change yoursite.com/section/subsection to
yoursite.com/content.php?a=section&b=subection or something, then you can
eliminate all the duplicate templates and just have your content files ( _make
sure you validate the section and subsection names_ ). Or you could plug in a
really simple database.

I'm no PHP expert, so if anyone has better ways of doing this kind of thing
I'd love to hear it.

(actually, I have a question: with this layout it's hard to pass data from
included files back up to the templates, like $title above needs to be defined
before the header include... is there some trick I'm missing?)

------
boucher
"Is there any reason to code the pages by hand anymore for a frequently
updated site?"

There hasn't been a reason to hand code anything that is at all dynamic or
frequently updated for a decade. There's a reason PHP is so popular after all.

That being said, any HTML/CSS that has to do with layout is still best done by
hand.

On the spectrum of tools available, what most people are looking for is a
hand-coded layout/template with something like wordpress/moveable type
generating the content.

------
thomasswift
I used to do a simple rails site for anything I put on the web. I switch to
html based site for things that I wasn't updating much. The reason was to save
on memory usage on my vps.

For a site of any complexity, I would use a cms, home-brewed or open-sourced
though.

Removing the database layer is always a nice option, but if you plan to have
any sort of interactivity, straight html might be a pain.

