I'm building a simple webpage. However there are a few dozen sub pages. The way this guy organises his business means the phone number is constantly changing between those in charge of taking calls any given week. Is there a way I can change a single line of text (say in a css file) and have the phone number posted on all the sub pages change every week according to who is in charge of taking the calls?
Since then I've learned just enough to change the template from a messy html/table code to a more streamlined look to the code using css.

- 8,084
- 8
- 48
- 62

- 1
- 1
-
1are you considering using a database? a template is a good start, but if is a plain html is gonna create a lot of problems to change all the phones... would be a lot easier if you bring that info from a DB – jpganz18 Dec 07 '15 at 20:10
-
http://stackoverflow.com/questions/2741312/using-css-to-insert-text – 001 Dec 07 '15 at 20:22
2 Answers
You COULD potentially do it via the ::after
pseudo-element if this fits your browser support profile: http://caniuse.com/#feat=css-gencontent
Note that IE8 (the only 'common' browser without support of ::after
instead of :after
) is EOL early next year (and there will be much rejoicing).
While this is an absolutely terrible way of doing this- you're supposed to use CSS for presentation not information, I'm not gonna tell you don't if this is just a temporary hack to save yourself a headache while you implement something less terrible.
Sample of how-to: http://dabblet.com/gist/b4bd30443cdbd810d8a8
Call <span class="data-onCallPhnNum"></span> for help.
.data-onCallPhnNum::after{
content:"(555)-555-5555";
}
Should note that the primary disadvantage of this is that there is no fallback if the browser cannot render the ::after
pseudoelement.
Better yet, you could include a Javascript file like this:
[....]
<script type="text/javascript" src="phonenum.js"></script>
</body>
</html>
and having the js in phonenum.js (and its expected HTML use) be:
(function(){
var phnNum = "(555)-555-5555";
var phnLnks = document.getElementsByClassName("data-onCallPhnNum");
for(var i = phnLnks.length >>> 0; i--;){
phnLnks[i].href = "tel:" + phnNum;
phnLnks[i].innerHTML = phnNum;
}
})();
Call <a href="page-with-phone-number.html" class="data-onCallPhnNum">the number listed on our contact page</a> for assistance.
This would accomplish the same thing, only not work on browsers with js turned off, has a natural fallback, has a clickable phone number for mobile viewers, and isn't using CSS for information.
You should still eventually move this into a database and have the number pulled server side, but for a hack to save on headaches before that real solution's ready, either'll do.
EDIT NOTE: Beers go to CBroe for suggesting the tel:
protocol and the formalization of the fallback.

- 1,266
- 9
- 17
-
1+1. Using a real link would give you the possibility of using the `tel:` protocol, so that mobile phone users can start a call immediately. I would perhaps combine your JS solution with a fallback in the form of a link `Contact us via Phone`, and then replace the `href` of that link via JS with `tel:+4X1234567`, and text content of the link with the "human readable" version of the number. The non-JS fallback would be the document `/contact_us_via_phone.htm`, that gets updated accordingly as well each time. [...] – CBroe Jul 01 '16 at 18:21
-
[...] Granted, two documents to change instead of one - but if customers being able to contact the business no matter what capabilities their device might have is important (and how could it not be), that should justify this little extra effort. – CBroe Jul 01 '16 at 18:22
-
Not to forget, that caching headers for both the .js and the .htm fallback resource should be set properly, to avoid customers who visit the site more often from been served outdated contact info. – CBroe Jul 01 '16 at 18:24
-
1@CBroe that's actually a really good idea. Think I'll slap the `tel` bit into this solution for other future views. Heh, meanwhile just today I did an edit to fix a use of "irregardless" vs "regardless" – abluejelly Jul 01 '16 at 18:25
There are two other options, neither on is strictly an HTML solution.
Server Side Includes are one option, though they are falling out of favor.
Another option is using a server-side template system, such as PHP.

- 23,369
- 6
- 54
- 74
-
Well now there's an unfortunate name. "Server Side Includes" being a webserver's automatic ones, rather than something like PHP's include(); system. The latter is how you're supposed to use PHP, the former is superseded by having a server-side language in use. Honestly didn't even know SSIs were a thing without a language attached. Good to know. – abluejelly Dec 07 '15 at 21:53
-
1Agreed -- which is why I made sure to include a link to that one. – Jeremy J Starcher Dec 07 '15 at 22:11