Jump to content
xisto Community
WeaponX

Adding Static Content To Website...

Recommended Posts

I want to add some static content to my website and was steering towards using SHTML files and the #include method, but hesitated on it. I currently have a big handful of .HTM files and don't want to convert them to SHTML (even though it shouldn't be much of a bother). I just like them to be .HTM files (use to it).

Is there any way to do something similar like the Server Side Include method above, but with HTM files instead? Usually the SHTML code will have some line like the below in it:

<!--#include virtual="mypage.html" -->

So if I just change that mypage.html, it will change it for all my other files using that line. Just FYI, one thing I want to use this for is the navigation menus - so I don't have to do this for every single file if I make some changes in my menus...and no, I don't use frames :D
Thanks.

Share this post


Link to post
Share on other sites

You can ues javascript to include a few lines of text, but it'd be very inconvenient.

First, make your external javascript file to include your menu:

<script src="menu.js" type="text/javascript"></script>
Just put that line of code in the pages that you want the menu to appear in.

Then, in your menu.js insert this code:
document.write('[I]<div id=menu><p>I/'m here!!!</p></div>[/I]')
That will make the javascript write the html code into your page. Change the code in italics into the code for your menu. You'll have to escape the quotes(') eveytime you use them by putting a / in front of it. That's why it's very inconvenient to use it.


I have to go now. If you want, I can tell you a way to use PHP to insert files into your pages. It's a much better way, but I don't know if you want it, since you said something about using html only? PHP can be inserted into html files and browsers will see them as normal html, so I don't see any problem in using them. (I use them to include file myself)

Share this post


Link to post
Share on other sites

Thanks for the reply szupie. I'll probably stay away from javascript for now.Yes, if you can provide an example on how to do this using PHP that would be great.The only reason I mentioned html files only is because Firefox seems to have problems with PHP files that have javascript in them. In my main page, I have a navigation menu in javascript and I remember changing my index.htm to index.php with some PHP code in it (used to pull my forum topics to display in main page :D) and it doesn't show up at all in Firefox. Internet Explorer and Opera doesn't have this problem. So right now I think the homepage is really a shtml file using the SSI method.I know some of the terminology here by researching them online, but really don't know much about PHP nor more "advanced" SSI methods. A simple example should be ok for me...just so I have a picture of how it works.

Share this post


Link to post
Share on other sites

Someone please answer me: what is static content?:D Sorry, but I was a little desperate. I don't know so many vocabulary and computer terms on design and web development, so you have to understand ;)Man, I'm so fond of people who can code :D

Share this post


Link to post
Share on other sites

If your browser doesn't display the PHP file properly, it's probably something wrong with the server. Go to your cpanel, and in the Advanced Tools section, go to Mime Types. Look for "application/x-httpd-php" in the long list, and make sure that it says ".php .php4 .php3 .phtml" after it. I'll tell you how to use the PHP method in another post in about 10 hours (when I get back from school).cyborgxxi: Static content is content that does not interact with the client (the web users). A page about the news is static content. A flash game is not. I don't think this forum is static content either (I'm not sure).EDIT: jlhaslip has a better explaination than me :D . Look at the next post.

Edited by szupie (see edit history)

Share this post


Link to post
Share on other sites

Someone please answer me: what is static content?

1064336057[/snapback]


"Static Content" is content on a web page that never (or rarely) changes. It only changes if you alter the content of the file and upload the new version, or use the cpanel text editor to edit it after it is uploaded. If the User requests the page several times, it will be the same result each time.

"Dynamic Content" is content which is constantly changing or is changeable based on a User's input. For example, using php to search a database and altering page content based on the search results is a dynamic process.

Share this post


Link to post
Share on other sites

I'm back, with instructions on how to use PHP for adding a menu on your pages.

 

OK, if your PHP configurations are correct, let's look at the actual coding. First, the basics of PHP: the server the contains your PHP file will parse your file as a normal HTML file. But when you put "<?php" inside your file, it would start parsing it as PHP code, until it find the text "?>", where it would stop. The concept is similar to (X)HTML, where everything inside a certain tag would be parsed according to the tag (Like words inside the strong tag would normally become bold). So,

<?php echo "Bob Saget!!!"; ?>
would make the server parse the PHP and print out "Bob Saget!!!" (without quotes). If you put
<strong><?php echo "Bob Saget!!!"; ?></strong>
, the server will first treat the strong tag as normal HTML (meaning it won't do anything), then when it sees <?php, it will start parsing the code and then sending it as HTML. Then, your browser would parse the HTML and display the elements inside the strong tag as bold, and you would see "Bob Saget!!!" in your browser (without quotes).

 

Now, the actual functions we're going to use: the include... Uh... *Goes to look up the correct word*... statement. The include statement can be used to include an external file inside your existing page (what a surprise!?). So suppose you have your menu file saved as menu.htm in the same directory as your other pages...

<?php include('menu.htm'); ?>
Put that code wherever you want the menu to appear on your page, and you're done. Or, almost done. You still have to make the menu.htm...

 

Inside your menu.htm, put in something like this:

Home<br/>About<br/>OMG A Page<br/>Bob Saget!!!<br/>I'm bored.<br/>More filler<br/>Stuff
If your menu is as basic as that, that's all you need in your file. If you follow web standards, use lists (ul) for your menu. You should not include the <html></html> tags in your file. It's a part of a bigger file, and it does not deserve individuality :D . But seriously. If you put <html> tags in, you'd have multiple of them in your file. That's not correct coding.

 

Extras:

1. You can also use the require statement instead of the include statement. With the Require statement, the file must be included in your page, or the server would send an error back to your browser. It's good if the thing you're including is crucial to the security your page, but for a simple menu, you can simply stick with include.

2. If there is one page where you want the menu to be displayed differently, e.g. making every word bold, you can put <strong> around the <?php ?> to make the whole menu bold.

3. If your file is located in a parent directory. No, make that a "grandparent" directory: change the file location to '././menu.htm'. Every "./" means a parent directory.

 

 

Fin.

Share this post


Link to post
Share on other sites

Thanks for that short "tutorial" szupie. Looks great and absorbed the material :D I'm sure PHP should work properly since I have the SimpleMachines Forum installed already. But will double check the settings.It's in a way similar to the SSI method...Is there any problem using one method (SSI or PHP) over another? I want to make it as problem-free as possible because as I mentioned earlier, I did have some slight problems with my menu displaying properly when my index page was a PHP file (it's a .shtml page now). But I will definitely experiment with this and probably change all my HTM pages to PHP.Just one more question. Any way to direct all HTM pages to PHP instead? Otherwise, I'll post a message on the site asking all users to update their bookmarks.Thanks again.

Share this post


Link to post
Share on other sites

I haven't tried using SSI, so I don't know how different it is. But I'm sure that it would be as problem-free as PHP.

You can use javascript to redirect your users to another page just add the following line of code in your page and it'll redirect to whatever page you want it to go to:

document.location = '/thepageyouwant.php';
Or, you can make the server parse your .htm files the same as .php files too. To do that, go to the Mime Types in your cpanel, and type "application/x-httpd-php" in the Mime Type box, and "htm" in the Extension(s) box. That would make the server parse even the htm files, which would increase server load a little bit. If most of your .htm files do not have PHP code in them, I wouldn't recommend doing this. But if they all have PHP code in them, it doesn't matter.

Share this post


Link to post
Share on other sites

Is there any problem using one method (SSI or PHP) over another?  I want to make it as problem-free as possible because as I mentioned earlier, I did have some slight problems with my menu displaying properly when my index page was a PHP file (it's a .shtml page now).  But I will definitely experiment with this and probably change all my HTM pages to PHP.

1064336105[/snapback]


SSI is a bit of an old technology to use. I don't have any factual knowledge but I believe it now is less commonly supported by web servers than PHP.

 

PHP is a still developing technology and so popular that I don't see it disappearing anytime soon, unline SSI. So definitely go for PHP includes, it will ensure that your code is working on any other server your site might be in the future. Oh and especially as PHP is a programming language unlike SSI you can later add some dynamic elements with it to the same page. It's rather inconvenient to try to mix dynamic content produced/included with different methods. As you mentioned that you have SMF forum running on your site, check out the page ssi_examples.php at your forums directory (access with browser). SMF has these nice little things that you can use on any page of your site. For example you could show the hottest discussion topics on your front page and so on. Check the examples and you'll understand. By the way, these elements are available for both PHP and SSI.

 

And one more final remark: PHP tends to run faster with includes than SSI. Not that it matters much though...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.