1

I'd like to create a template html file that loads content from a text file so that I don't have to change the html if I want to change text content. I'd like this text to be interspersed with images so I'd like to be able to reference each paragraph from the text individually. Thus, I'm looking for something along the lines of:

<div><p txt= [first paragraph from file.txt]></p></div>
<div><p txt= [second paragraph from file.txt]></p></div>
<div><p txt= [third paragraph from file.txt]></p></div>
<div><p txt= [fourth paragraph from file.txt]></p></div>
...

where file.txt is specified once at the beginning of the html file and the number of paragraphs in the text file might be variable. I suspect I'll need to use javascript. Is there a way to load each paragraph into some variable that I can reference to change each text attribute? To my knowledge [previous solutions][1] have loaded the entire text file as a single text chunk.

making a paragraph in html contain a text from a file

DerekG
  • 3,555
  • 1
  • 11
  • 21
  • Why not have the document just as the HTML and put it into the file? If you do't do that, just split on the new lines and loop over.... – epascarello Jul 30 '21 at 13:10
  • I don't follow what you mean here "have the document just as the HTML and put it into the file" – DerekG Jul 30 '21 at 13:12
  • So you make a fetch or Ajax call, you grab the content with it. You put it into the document. – epascarello Jul 30 '21 at 13:37
  • For technical reasons (hosting on github pages which does not support ssl / Ajax requests, see following link) I cannot use Ajax. Thus, I'm looking for a solution that uses only Javascript/html. https://stackoverflow.com/questions/38433099/github-io-blocked-ajax-request – DerekG Aug 02 '21 at 10:29
  • If you need to load it from an file, you need to make an Ajax/Fetch request. So if you can not do it, well you are out of luck. – epascarello Aug 02 '21 at 12:26

0 Answers0