Current time: 04-23-2014, 03:47 AM Hello There, Guest! (LoginRegister)

Post Reply 
Managing repetitive code. CSS/HTML??
03-03-2008, 08:07 AM
Post: #1
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.

Chili
Find all posts by this user
Quote this message in a reply
03-03-2008, 08:18 AM
Post: #2
Managing repetitive code. CSS/HTML??
Are you programming in PHP or just using static HTML pages with CSS?

Use the 3DOM50 promo code for 3 extra lifetime domains and $50 off
More Dreamhost coupons here!
Find all posts by this user
Quote this message in a reply
03-03-2008, 08:32 AM
Post: #3
Managing repetitive code. CSS/HTML??
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 >
http://wiki.dreamhost.com/SSI

$50 off and 3 free domains with code: DH3 Sign Up NOW or More Codes Here
Visit this user's website Find all posts by this user
Quote this message in a reply
03-03-2008, 09:56 AM
Post: #4
Managing repetitive code. CSS/HTML??
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:
Code:
<?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
include($_SERVER['DOCUMENT_ROOT']."/includes/funcs.php");

// database connection
include($_SERVER['DOCUMENT_ROOT']."/includes/db.php");
?>
<html>
<head>
<title>Whatever</title>
<?php
// metadata and style sheets
include($_SERVER['DOCUMENT_ROOT']."/includes/style.php");
?>
</head>
<body>
<?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");
?>
</body>
</html>
-- si-blog --
Max discount on any plan with promocode SCJESSEYTOTAL
Visit this user's website Find all posts by this user
Quote this message in a reply
03-03-2008, 11:14 AM
Post: #5
Managing repetitive code. CSS/HTML??
You need to do this on the server side with php or .net or vbscript (asp), etc.
Find all posts by this user
Quote this message in a reply
03-03-2008, 06:06 PM
Post: #6
Managing repetitive code. CSS/HTML??
Static HTML and CSS....
thanks.
Find all posts by this user
Quote this message in a reply
03-03-2008, 06:07 PM
Post: #7
Managing repetitive code. CSS/HTML??
Thanks. I'll give it a try.
Find all posts by this user
Quote this message in a reply
03-03-2008, 08:16 PM
Post: #8
Managing repetitive code. CSS/HTML??
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: DH3 Sign Up NOW or More Codes Here
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: