开发者

Stylesheets for content?

开发者 https://www.devze.com 2023-01-04 21:17 出处:网络
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 chan开发者_开发技巧ges in my CSS throughout several pages th

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 chan开发者_开发技巧ges 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.


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.


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.


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!


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.


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.


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.


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..


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消