views:

86

answers:

8

Forgive my ignorance since this seems like its something I should know by now.

I know I could make a stylesheet that will allow me to make changes in my CSS throughout several pages that use the CSS. I also know that you can make an external javascript file that could contain functions you want to reuse. But lets say I had pure HTML content (lets pretend a bunch of buttons or links) that I wanted replicated on several pages. Is there anything similar to a stylesheet in that regard? This would allow you to update the buttons/links all at once.

A: 

You can try using the CSS content property, but the content is inserted after/before the target. http://www.w3schools.com/Css/pr_gen_content.asp

EDIT

You can also try storing your content in XML documents and using JavaScript to load the XML sheets. Each sheet can store your button content, input content, etc. All you have to do is parse the XML and render the content as HTML elements.

SimpleCoder
This is poorly supported in IE. Not a good idea.
Moshe
Yup - sadly, true. Not a good idea, at least not yet.
Pekka
True. Hopefully it's incorporated better in later releases
SimpleCoder
+3  A: 

Try server-side includes.

The most frequent use of SSI is to include the contents of one or more files into a web page on a web server. For example, a web page containing a daily quote could include the quote by placing the following code into the file of the web page:

You could also use PHP, if your host allows it. Just change the name of the page from .html to .php and reference the header:

<?php include "header.php" ?>

Both of these require you to change the file's extension, so you might also want to use mod_rewrite to let users still access it via the .html name. Again, if your host supports it.

Simon Brown
A: 

It seems you're not using some server side technology like ASP.NET which has user controls on which you could place those.

An alternative would be to use Server Side Includes like:

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

Grz, Kris.

XIII
+1  A: 

The question isn't that stupid, as there in fact is nothing native in HTML to do this.

If supported by your server, Server Side Includes are your best option. If you have PHP, you can also do a <?php include "footer.html"; ?>

All other server side languages have a similar construct.

Pekka
+1  A: 

Depends... I know Dreamweaver has some rather advanced support for templates. You can delve into the manual of your WYSIWYG HTML editor and get acquainted to how it can help you with repeatable content items. Otherwise, as Simon hinted, you should consider learning some server side technology (scripting language such as PHP is an easy choice), write your repeatable HTML and let the scripts output that whenever and wherever you need. Good luck!

Peter Perháč
A: 

While SSI seems like the best idea I believe, if memory serves me well, that if you're using IIS you're going to have to adjust some settings on the server to work get SSI with the html file extention.

While SimpleCoder's idea doesn't seem like the best idea it is an interesting one. Building on that idea maybe json data instead of xml would be best. I'd play around with this just for the fun of it.

August Blaze
A: 

If neither SSI or PHP is available, you could do it with javascript only: Load the page into a hidden IFRAME, then grab it (with innerHTML) - and move it to where you need it..

T4NK3R
A: 

Unless you don't care about SEO, I would advise against using javascript for this purpose.

It's possible, but such a technique could prevent search engines from properly indexing your site.

Chris Fletcher