Managing repetitive code. CSS/HTML?



Is there a way to keep repeating code, like navigation links, in a separate file so I don’t need to update multiple files? How would I do this? I have intermediate HTML/CSS programming skills with a beginning knowledge of Javascript.

Thank you.



Are you programming in PHP or just using static HTML pages with CSS?

Use the [color=#CC0000]3DOM50[/color] promo code for 3 extra lifetime domains and $50 off
More Dreamhost coupons here!


You can achieve that by using either PHP or SSI (Server Side Include). Both are enabled in DH.

If you do not mind to use PHP, you can:

  1. rename your .html file to .php file
  2. in .php file, use command require_once(“filename.php”); to include a file

If you are not comfortable with PHP, you can use SSI

  1. rename your .html file to .shtml file
  2. in .shtml file use command < !–#include virtual=“yourfile.html” – > to include a file. Note there is no space between < and – and no space between – and >

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here


If you are using PHP, and if your file structure includes subdirectories, your best bet is to create a new folder (“includes”, perhaps) in the web root directory that contains the sections of code you wish to include and then use the following line of PHP to “include” them:<?php include($_SERVER['DOCUMENT_ROOT']."/includes/nav_links.php"); ?>You can have as many of these as you like. I typically use includes for database connections, common functions, headers, footers and navigation. A simplified example of a typical PHP-based web page might look like this:[code]<?php
// common functions

// database connection

Whatever <?php // metadata and style sheets include($_SERVER['DOCUMENT_ROOT']."/includes/style.php"); ?> <?php // header include($_SERVER['DOCUMENT_ROOT']."/includes/header.php"); ?>

… main content…

<?php include($_SERVER['DOCUMENT_ROOT']."/includes/sidebar.php"); include($_SERVER['DOCUMENT_ROOT']."/includes/footer.php"); ?> [/code]-- [url=][b]si-blog[/b][/url] -- [b]Max[/b] discount on [i]any[/i] plan with promocode [url=|SCJESSEYTOTAL][b]SCJESSEYTOTAL[/b][/url]


You need to do this on the server side with php or .net or vbscript (asp), etc.


Static HTML and CSS…


Thanks. I’ll give it a try.


You are welcome.

Please note that all hosting plans in DH are on unix so you can’t use .net or vbscript.

$50 off and 3 free domains with code: [color=#CC0000]DH3[/color] Sign Up NOW or More Codes Here