2

I've got an index.html file for use with Jekyll and would like the contents of one paragraph in the HTML file to be called from a text file ("stuff.txt") located in the same directory as the index.html file.

Is there a simple HTML command to read in the text, preferably outwith the use of PHP or JavaScript?

Nimeshka Srimal
  • 8,012
  • 5
  • 42
  • 57
Jim Maas
  • 1,481
  • 2
  • 16
  • 36

5 Answers5

5

If you really do not wish to use js or php, here is a solution. Use the embed tag to embed the text file into your document. Otherwise, you can use an iframe too.

  <embed src="stuff.txt">

Reference Link : http://www.quackit.com/html_5/tags/html_embed_tag.cfm

Nimeshka Srimal
  • 8,012
  • 5
  • 42
  • 57
3

without php

<iframe src='stuff.txt' scrolling='no' frameborder='0'></iframe>

just tested and it works . Or try it with php as bellow

<iframe src='txt.php' scrolling='no' frameborder='0'></iframe>

and txt.php

<?php
echo file_get_contents("stuff.txt");
?> 
3

This actually seems to work:

<object width="1000" height="200" data="stuff.txt"></object>
Stefan
  • 3,850
  • 2
  • 26
  • 39
  • Why the downvote? It works, and directly answers the question. – Stefan Sep 18 '14 at 10:01
  • It's invalid (not the object element itself, but the usage here) and inferior to an iframe. – Quentin Sep 18 '14 at 10:02
  • @Quentin: 'Inferior to an iFrame': Is that a subjective opinion? Why is it inferior to that? And I ran this through the validator at http://validator.w3.org/check and it is valid (after I replaced the width and height values I used originally). – Stefan Sep 18 '14 at 10:07
  • This does work, however is displayed in a small inferior font. Now to see if I can get it displayed in the correct font and size as when the text is written directly in the html file. – Jim Maas Sep 18 '14 at 10:08
  • @user207146 I suspect you will have the same problem with an iFrame. – Stefan Sep 18 '14 at 10:08
  • Iframes have been better supported for longer, and have better specified and supported APIs for interacting with in JS. Also, if you had to fix it to make it valid, it wasn't valid in the first place, was it? – Quentin Sep 18 '14 at 10:09
  • @Quentin: Yes it was invalid because of my sloppy original attribute values/typos, but not because the concept is invalid. I would be surprised if there is a support problem or lack of adequate documentation for `object` in any context where `iframe` can be used too. – Stefan Sep 18 '14 at 10:15
2

Since you are already using Jekyll, just use its built-in include mechanism:

{% include stuff.txt %}
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • This works well for Jekyll as long as the file is placed in the "_includes" directory. It works even better if the file included is in .html format, then can include live links and all the other stuff. Very good solution ... thanks. – Jim Maas Sep 18 '14 at 10:53
1

You need to use PHP or Javascript, but there's an old-fashioned way that you can use called Server-Side Includes:

http://www.htmlgoodies.com/beyond/webmaster/article.php/3473341

You will need to rename your file to index.shtml and write something like:

<!--#include file="stuff.txt" -->

Update per comment: You need to be on a server that supports SSI. From my experience, most shared hosting servers support it, but you might need to ask your host.

Ynhockey
  • 3,845
  • 5
  • 33
  • 51