Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using the Include statement

Status
Not open for further replies.

Chomauk

Programmer
Jun 8, 2001
130
I'm pretty much a newbie and have been programming with several new languages lately for web development. Anyway as I've been coding it seems that a developer would want to create many different files consisting of code to do specific things and then use the include statment when needed in other files. This helps(me) keep everything better organized. I have a page(s) for my CSS code, banner, menu, Login/Register code, etc... I don't see this happening when I view others source code. Am I doing this properly or is there a better way I should be doing my web development? Any advice would be greatly appreciated. By the way I'm using HTML, JScript, VBScript, CSS, PHP, ASP, MYSQL.

Thanks very much

 
If you're talking about the SSI include statement, you're absolutely right - it's the best way to organise your page (though your CSS should be in a seperate file that you <link> to, rather than included inline into each page).

The reason you don't see other people doing it when you View Source is that the Include is processed by the server - it replaces the include statement with the relevant file - so by the time your browser sees it you can't tell what was included and what wasn't. That's what makes SSI so good - it doesn't rely on anything from the client, it just serves up normal HTML (or whatever).

If you're looking for a tip on how to arrange your includes, I'd do it like this:
[tt]
<html>
<head>
<title>My template page</title>
<!--#include virtual=&quot;/headtags.txt&quot; -->
</head>
<body>
<!--#include virtual=&quot;/bodytop.txt&quot; -->

<h1>Template</h1>
<p>Content of the page goes in here</p>

<!--#include virtual=&quot;/bodybottom.txt&quot; -->
</body>
</html>
[/tt]
The idea being to keep the includes as generic as possible. That way, when you redesign the page you can change the three .txt files without having to make any changes to all the content pages.

-- Chris Hunt
 
Thank you very much. I mistakenly added the CSS file as an example. Can I use the include with any type file like asp, php?
 
Good answer. Thanks for the prompt & helpful responses.

 
I believe ssi and asp are similar

php includes are

<? include (&quot;filename.extension&quot;); ?>

<Signature>
Sometimes the Answer You Are LOOKING for can be FOUND BY SEARCHING THE FAQ'S @&%$*#!!!
</Signature>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top