Importing Text into Webpage?

Just wondering if anyone could help me with a problem I am having. I need to have a lot o webpages that pull a line of text from a txt file so that when the file is changed, all the HTML files will have the new info when they start.

Any ideas? Please let me know.:slight_smile:

You’ll need to look into server-side includes such as PHP or even simple server-side-includes where you usually write a simple file to be included and inserted by an include script. Typical uses being navigation menus, etc.

Yeah, it depends on the technology that your server uses.

I use ColdFusion, and it’s AMAZINGLY simple to do this. For example


<cfset message="Hello World" />


<cfinclude template="inc-data.cfm" />
<p>The message is: #message#.</p>

Mein gott! Coldfusion?!? and here I was ragging on the people actually using ASP… what is this, 2001?

I though CF was long dead and buried… for good reason!

This is a client side solution. The text block to add is in a .js file which can be accessed by each page. The rest is a simple document.write at the position you want the block.

The javascript file has a concatenated string using “+” to keep the file width suitable for reading in this example. Note that the block has all HTML tags in place, so it renders as part of the page immediately.

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">


<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Adding Text to all pages</title>
<script src="addBlock.js" type="text/JavaScript"></script>

<script type="text/javascript">
<p><b>Beginning of next paragraph</b> ..........</p>



/* ------ block of text to add to any page ---------- */
var textBlk="<p><b>Appended text</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit."+
 " Fusce ipsum felis, eleifend ut congue mattis, iaculis ac quam. Nam luctus scelerisque felis, ac adipiscing metus facilisis in.</p>"+
 "<p>Nullam et nisl eu justo luctus sodales in varius arcu. Nunc enim leo, laoreet vitae dapibus eget, malesuada nec erat."+
 " Nunc bibendum sapien vel lorem laoreet lacinia. Vestibulum tortor elit, ultrices vitae luctus quis, iaculis non libero.</p>";

Sorry, but that’s just plain awful. Relying on Javascript to include essential content is totally unacceptable, because it fails completely for users who haven’t got Javascript running (and that could well include Googlebot).

Using server-side includes (or PHP) is a much better solution, which doesn’t rely on visitors having anything other than a basic HTML reader so will work on any browser and any configuration/setup.

I was converted to SSI several years ago and never looked back. It’s very simple to use, the only slight fiddle is to make sure that all relevant pages are read as SHTML, but even that is pretty easy once you know what to do.

@allanP – I’m with Stevie on that – How to take a perfectly good website and flush it down the crapper by making it not only an accessibility train wreck, but also a convoluted mess to maintain AND probably going to suck down more bandwidth and processor time (thanks to IOWAIT on the transfers) than just handling it server-side.

Remember, Javascript should enhance functionality, NOT SUPPLANT IT.

Of course, with scripted “web apps” being the new buzz of pointless bloated bull being thrown at websites like crazy… Is it any wonder half the people asking for help around here end up with 500 megabyte firstloads in hundreds of separate files to deliver 5-10k of plaintext and two content images?

Lol. Must be lonely living in your own world of fantasy. Tell me, are you king there, or court jester?

CF has knocked the blocks off each and every web app I’ve been tasked in making. I don’t know where you’re getting your decade old statistics, but the latest edition of CF, version 9, came out October 5, 2009. ColdFusion X (or CFX) is in talk now and scheduled for release shortly down the line.

You know Aaron. There are those days that I simply not react! :slight_smile:

Hey, if they made a comment to me, the LEAST I can do is respond. :wink:

It’s also been a misconception widely held that I like to dispell. I know as with many other things, programmers are VERY defensive of their language of choice. I don’t go around converting people to CF, but if they’re asking for a language to get into, I highly recommend it.

I always think, as long as I happy with it, why should I care what others say. I just remember a post here on SP comparing CF and PHP. It was about the difference in the way PHP and CF are using output. I couldn’t find it back but remembered sharing it with someone on skype. Here is what someone posted:

while($row = mysql_fetch_object($query)) {
                     $set[$row->postyear][] = $row->entry_name;
                     $ids[$row->postyear][] = $row->entry_id;
                     $dates[$row->postyear][] = $row->postdate;
              foreach ($set as $postyear => $rows) { 
                     echo "<h4>{$postyear}</h4>\
                     echo "<ul>";
              foreach ($rows as $key => $entry_name) {
                     echo "\
\	<li><a href=\\"index.php?entry={$ids[$postyear][$key]}\\" title=\\"Posted: {$dates[$postyear][$key]}\\">{$entry_name}</a></li>";
                     echo "\

<cfoutput group="postyear">
<cfoutput><li><a href="index.php?entry=#entry_id#" title="Posted: #postdate#">#entry_name#</a></li></cfoutout>

That’s enough reason for me to be happy with CF

and that’s a perfect example of someone writing php incorrectly… or as I like to call it, “Hey <expletive deleted>, it’s called single quotes”… much less whatever query is being run before that is obviously NOT pulling the appropriate data if you have to nest a foreach in the while… wll, that and somebody needs to learn how to use the tab key correctly :smiley:

Of course the CF code posted next to it has no logic flow – and is absurdly vague as to what it’s actually doing/accomplishing, which I guess was always my real problem with it…

Well that and it behaves like inline scripting instead of an actual programming language. I don’t like it when people do fifty-million <? ?> in their PHP either - as that too kind-of defeats the point.

As long as it is logic to me, I’m okay with it deathshadow60 :wink: