views:

65

answers:

4

Hi,

I have a contact css tab on my left side on my website, I have more then 30 pages and I don't wantto manually alter all those pages later when data had changed. Does anyone knows a sollution so I only have to alter 1 file to have all pages edited?

Perhaps in javascript?

The code below is for the tab

<div class="slide-out-div">
        <a class="handle" href="http://link-for-non-js-users"&gt;Content&lt;/a&gt;
      <h3>Onze contact gegevens</h3>
        <p>Adres: van Ostadestraat 55<br />
          Postcode: 8932 JZ<br />
        Plaats: Leeuwarden<br />
        Tel: 058 844 66 28<br />
        Mob: 0629594595
        <br />
        E-mail: <a href="mailto:[email protected]">[email protected]</a><br /><br />
        </p>
<p>Mocht u vragen hebben dan kunt u gerust bij ons terecht voor meer informatie.</p>

Edit:

This is in my html

<!--#include virtual="contact.txt" -->
  </body>

and this is in my contact.txt which is located in the rot of my webfolder:

<div class="slide-out-div">
        <a class="handle" href="http://link-for-non-js-users"&gt;Content&lt;/a&gt;
      <h3>Onze contact gegevens</h3>
        <p>Adres: van Ostadestraat 55<br />
          Postcode: 8932 JZ<br />
        Plaats: Leeuwarden<br />
        Tel: 058 844 66 28<br />
        Mob: 0629594595
        <br />
        E-mail: <a href="mailto:[email protected]">[email protected]</a><br /><br />
        </p>
<p>Mocht u vragen hebben dan kunt u gerust bij ons terecht voor meer informatie.</p>
+3  A: 

Create a text file with the relevant HTML/text and put this into your HTML where you want it to appear.

<!--#include virtual="path to file/include-file.txt" -->

Hope that helps :)

UPDATE:

After the lengthy discussion, rename your pages to .php instead of .html and your contact to .php instead of .txt and use this to include your file:

<?php include('contact.php'); ?>

If your pages are in different directories, use:

<?php include($DOCUMENT_ROOT . "/path-to-files/contact.php"); ?>

This will force the page to look at the root directory of your site.

Kyle Sevenoaks
+4  A: 

You may want to use Server Side Includes (SSI).

You would place your code snippet into a separate file, such as contact.txt, and then you would simply reference it in all your 30 pages by using:

<!--#include virtual="contact.txt" -->

SSI is supported by all the popular web servers, including Apache, IIS and lighttpd.

Daniel Vassallo
great! thanks!!
Chris
For some reason it does not work, I have edited my question
Chris
@Chris: What web server are you using? SSI might be disabled... When you open your html page from your web browser, and you click 'View Source', do you find the `<!--#include virtual="contact.txt" -->` comment? If yes, SSI is disabled. If not, then most probably it is just the path that is incorrect.
Daniel Vassallo
Apache/2.2.8 (Ubuntu) PHP/5.2.4-2ubuntu5.5 with Suhosin-Patch
Chris
I wonder why did this got downvoted?
Daniel Vassallo
it's litterly included in the source as copied into the sourcecode. The paths are ok, it's indeed disabled then. Any other options?
Chris
php include maybe?
Chris
@Chris: You may want to follow this brief tutorial to enable SSI: https://help.ubuntu.com/community/ServerSideIncludes... And yes, php might be another option.
Daniel Vassallo
Very strange this is disabled. Maybe change your hosting provider. And I also wonder why it was downvoted.
Kyle Sevenoaks
@Chris: Also, try renaming your *.html file to *.shtml, and check it from your web browser. If this works, then you can still enable SSI for all html files, so that you would not need to rename all your files to shtml.
Daniel Vassallo
I just contacted the hosting provider. It's a shared hosting, that's why it's disabled. php include works indeed.
Chris
@Chris. You can use php include then, but I suppose you would have to rename all your 30 pages to *.php... Here's a short tutorial on php include: http://www.w3schools.com/PHP/php_includes.asp. Basically you would just need to do `<?php include("contact.txt"); ?>`
Daniel Vassallo
I knew that one thanks!
Chris
A: 

As I Accept both Daniel and Kyle solutions (and I +1 their answers)

If Iwere inyour situation. I maked a html with your contact info and then include it with a frame into 30 other pages like

  • contact.html (which includes only contact info)
  • page1.htm
  • pagex.htm
  • page30.htm

and in one pagex.htm put following code

<body>
     Other part of page ....
     <iframe id="contact" src="../contact.htm"></iframe>
</body>
Nasser Hadjloo
I rather not work with iframes
Chris
+1  A: 

As suggested, you can user Apache's SSI. That depends on that specific webserver and module being used.

To achieve that result you could either do two things:

Use some kind of templating language that supports it, and "compile it" before uploading to your webserver. Using ruby's ERB is one example.

Other is to use a server-side programming language (I'd recommend PHP as it's simple, easy to deploy and lot's of documentation around) to do that for you on the server.

Here is a simple example of that using PHP: http://www.albinoblacksheep.com/tutorial/include

Alcides