Forum Moderators: open

Message Too Old, No Replies

Shared file for two pages

Same code needed for two pages

         

Adam5001

1:28 pm on Jul 15, 2018 (gmt 0)

5+ Year Member



In reference to a post I made last week, I'd like to know how to create a file for code that is used by two pages. If I have the code "HTML code" that's used on two pages, how do I create a a file that has the code "HTML code" in it, and link both pages to it.

Or in other words, how do I write a piece of code, and have two pages share it?

Help!

Dimitri

2:22 pm on Jul 15, 2018 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member Top Contributors Of The Month



If you can use PHP, you can add in your page
<?php include "/path/something.html"; ?>

I am no longer using Apache since ages, but I think the mod_include might help too.

not2easy

4:34 pm on Jul 15, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



If this is related to your previous question Do I need this code? [webmasterworld.com] that is not HTML, it looks like GA javascript. Asking this question with that information might give you a different answer. I don't think you want to create a .html file without any html in it.

Also think about bots crawling that .html include page. You wouldn't want that to happen.

lucy24

6:01 pm on Jul 15, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you're not ready for php, then you need an SSI (Server Side Include [httpd.apache.org]). The stuff you include doesn't have to have the same extension as the primary page; for example it's common to include php navigation elements on an otherwise-html page. Note in particular that you do not need to change your existing pages to .shtml, so long as you've got the appropriate AddOutputFilter line. The “include virtual” syntax is best for most purposes.

keyplyr

8:04 pm on Jul 15, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Depending on your server config, you may need to "turn on" Server Side Includes (SSI). One way to do this is to add these line to your .htaccess file (found in your account root.):
AddHandler server-parsed .html
AddOutputFilter INCLUDES html
But I would check with your server admin to be sure of the exact syntax.

Sorry, our WW server won't let me post an SSI example to put on your pages, but the link lucy24 posted should have an example.