Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is It Possible to use an exteral file 3

Status
Not open for further replies.

JavaUser123

Technical User
Apr 22, 2007
8
GB
Is It Poss To Use HTML and An External .txt file To Link The Two
I Am Planning My .txt File Will Have The Body Text Needed on the HTML, So I Don't Have A Massive Code [ponder]
 
Hi

Do you mean to insert the .txt file's content into the .html file as its proper content ? You can do it with SSI if your web server supports them :
Code:
<html>
<body>
<!--#include file="content.txt" -->
</body>
</html>
Code:
Welcome to my site !

Feherke.
 
Just Tested It And It Doesn't Work, Is There Some Kind Of <script> Tag I Need To Use??
 
I've Just Found The Problem. I Am Using This Code And loading It Into My Web Broswer, And My .html File Needs to be a .shtml File. Is There Any Other Way Of Doing This, So I Will Get Results By Just Looking At It Through My Web Browser, And Will I Have To Use The .shtml extension?
[ponder]
 
Hi

JavaUser123 said:
Is There Some Kind Of <script> Tag I Need To Use??
No, there is no such thing. Tags are interpreted by the browsers and the browsers deal with complete pages only. Composing the page from pieces must be done on the server.
JavaUser123 said:
My .html File Needs to be a .shtml File. Is There Any Other Way Of Doing This, So I Will Get Results By Just Looking At It Through My Web Browser, And Will I Have To Use The .shtml extension?
The extension must match your web server's configuration. The .shtml is just the most common. If you configure it so, the extension may remain .html . But is not recommended. The distinct extension is used to not put the web server to parse all plain .html files for SSI code even if there is none.

You can do that with any other server-side programming language. For example PHP ( more in forum434 ) :
Code:
<html>
<body>
<?php include "content.txt"; ?>
</body>
</html>
But as you can see, the extension should be changed even there. By default. If you not want to, is again matter of web server configuration.

For your task of just inserting another file, I would say the SSI is more than sufficient.

Feherke.
 
You could create an iframe with HTML and give it the URL of the text document for it's source attribute.

Not ideal, but it will suit your purpose.


<honk>*:O)</honk>

Tyres: Mine's a pint of the black stuff.
Mike: You can't drink a pint of Bovril.
 
If you are going to use a SSI in this syntax:

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

You need to save your shtml file as a .asp file.

SSI are not understood by HTML or the like.


[monkey][snake] <.
 
Hi

monksnake said:
If you are going to use a SSI in this syntax:

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

You need to save your shtml file as a .asp file.
Excuse me monksnake, but I do not understand you. If it is SSI, how the save it as .asp file ? My site is powered by SSI, but I never touched .asp files.

Feherke.
 
The syntax of this particular SSI:
Code:
<!--#include file="content.txt" -->

is ASP code. I tested yesterday by including a .txt file into a .html file. The SSI didn't work. I then changed the extension to .asp. Then the file I specified in the SSI was included.

You may be using php for your SSI. In that case, ASP isn't even in the picture. I was just saying if you use the syntax I specified at the top of this post, the file that contains this include needs to be a .asp file.


[monkey][snake] <.
 
Hi

monksnake, I become more and more confused.

When I configure my web server to parse the .shtml file with its SSI module and the web server accomplishes the task using the SSI module, then that it is SSI. And can not be ASP because there is no ASP, even more, no Microsoft software beside.

Until now I used SSI with 3 web servers, each with its own implementation of SSI interpreter, none with ASP.

Feherke.
 
Ok, let me start from the beginning.

You are correct when you say you can use a SSI in .html files. I was wrong. That will only allow files to be included that have a certain extension (default .shtml) based on web server settings.

If you need to include files with any other extension though, a server side language is needed.

I was confused, so I can see why you were.

[monkey][snake] <.
 
monksnake, you would be incorrect. The code you have posted uses the syntax of server-side includes a simple web language that was created for simple server side manipulation. You will notice that given is not asp code, because it does not follow the standards in which asp code is written, nor do you include this code inside the asp delimiters in a file (<% %>). I am not sure what exactly is the deal with asp and includes, but it looks like asp simply uses the SSI code, rather than introducing its own syntax.

That said, in order for the server to parse SSI code, default extension of .shtml must be used. There are other extensions possible, mainly the ones that deal with processing any kind of server-side code, but by default .html will not parse SSI. Having asp installed on the server makes no difference in support of SSI.

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
Hi

monksnake said:
That will only allow files to be included that have a certain extension (default .shtml) based on web server settings.
Got it. So you talk about the included file, not the includer. Sorry, but still I can not agree. The included file can have any extension. The difference is only regarding possible SSI code in the included file.

Think about. It is possible ( with most SSI implementations ) to include not only files, but command output too.

Feherke.
 
What is confusing you guys? I believe my explanation had it all.

1. SSI is a separate language.
2. ASP does includes by using the syntax of SSI.
3. SSI exist on just about every server and are by default parsed in .shtml files. In addition, it is parsed in most server-side extensions (.php, .asp, .jsp, etc.)

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
Oh I understood Vragabond, I was shocked at this statement:

feherke said:
I will think twice in the future before recommending W3Schools to beginners.

[monkey][snake] <.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top