I have text that is repeated on multiple pages. Is it possible have the text in the external css page so I only have to change it one time?

Recommended Answers

All 8 Replies

If with text you mean content, than no. CSS is for styling only. Don't know how your site is built and what technologies you use, but some kind of templating would solve your problem.

You could use jquery or javascript for this. You could use PHP as well.

server side includes are designed for just this situation.

You have a choice of methods but most reliable these days is using PHP.

So if you have a little bit of text (or even lines of code) in a text file.
e.g. incsometext.txt (you can call this anything you like to fit in with your naming conventions)

...then in every place that you want the text you call the file with:

<?php require_once('incsometext.txt'); ?>

(Just in case you didn't know... a page that uses PHP has to end with .php instead of .htm)

Member Avatar for diafol

Actually you can have content via css. It's called the content property and it's used with after: and before: pseudo-elements. However, IE (it's always IE, isn't it?) only supports it from version 8.

e.g.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style type="text/css">
div.content:after {content: "Roll up, roll up";}
</style>
</head>

<body>
<div class="content"></div>
</body>
</html>
commented: Never come across it ... +5
Member Avatar for diafol

Thought I should clarify my post somewhat. css content is probably not the way to go. I, personally would not use it as there are so many users without v8+ of IE. Grr, pesky Microsoft! I'd go along with pritaeas - a templating system is what you're looking for - this can be as simple as having include files (require/include) or as complicated as a full-blown templating system (smarty, rain tpl etc). Anyway, I just wanted to suggest - don't use the css option for a year or so, until IE8 uptake by IE users is close to saturation (might never happen!).

(Just in case you didn't know... a page that uses PHP has to end with .php instead of .htm)

Just so you know, this is not true. On apache you can use any extension you want and treat it as a php file.

Just so you know, this is not true. On apache you can use any extension you want and treat it as a php file.

Just so you know, this is often functionally true. apache server is configurable, however, many servers, particularly low end hosting packs, are locked down
/* addhandler server-parsed is disabled */
so that configuration cannot be changed,

plan on the worst, and you get pleasant surprises when you find the result is better than you expect
plan on the best, and the only surprises are unpleasant

commented: Point taken +5

Thanks everyone! I appreciate all the input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.