View Full Version : Question about "Include" in shtml
harv
07-02-2002, 03:55/03:55AM
Is there a way to pass parameters to an
include file within in an shtml file
so that you can effectively have a constant
block of code with a variable item of text ?
Harvey
ihelpyou
07-02-2002, 08:15/08:15AM
hey harv, good to read you again! :hi:
I don't know that answer. Anyone? :)
crifer
08-02-2002, 10:17/10:17AM
That wouldn't be a problem but i really don't get the mening of it? Do you have an example?
harv
08-02-2002, 10:36/10:36AM
Here's an example of what I'm trying to say.
Suppose I want to repeat a large section of text
on many pages. I would give each page an
shtml suffix and have a command such as
<!--#include virtual="x.htm" -->
Now, suppose there is a number within this section
which needs to be different for each page.
I would like to say something like
For page 1:
set n=1
<!--#include virtual="x.htm" -->
For page 2:
set n=2
<!--#include virtual="x.htm" -->
so that the value of n appears in the
appropriate place
Harvey
crifer
08-02-2002, 11:18/11:18AM
Aha... That is easy, I don't know what language you use. I program in php and to include in an include file is not a problem.
Example:
Your include file looks like this and the name is name_include.php :
<p>My name is <? echo $name; ?></p>
--------------------
The page to display look like this:
<?php
$name = "crifer";
?>
<!-- The output file would look like this -->
<html>
<head>
</head>
<body>
<? include("name_include.php"); ?>
</body>
</html>
You have to put the variable that is containing text in the include file.
harv
08-02-2002, 12:17/12:17PM
Hi Kristoffer (I assume that's your first name).
You've lost me - I don't know anything about php.
Harvey
crifer
08-02-2002, 14:01/02:01PM
Yep, that my first name :)
What language do you program in?
My english isn't so good all the time (im swedish). I'll try explain it again.
If you want a value inside your include file you have to put the variable that hold that value inside that file.
Another example:
Variable containing the value volvo:
$thiscar = "volvo";
Inside the include file:
So, you need a $thiscar
----------
You have to give $thiscar a value before the include file is displaying. And the include file must contain the variable $thiscar
harv
08-02-2002, 15:10/03:10PM
Originally posted by crifer
What language do you program in?
I'm not sure about a 'language'.
I am simply setting up a .shtml file with
the basic html commands and calling,
via an include instruction , a .htm file
Harvey
crifer
08-02-2002, 15:23/03:23PM
Hmm.. Then you might have to use javascript or other language.. Html don't have the ability to parse document or pass values to other douments via the header...
What do you want to affect in the included file?
harv
08-02-2002, 16:23/04:23PM
Originally posted by crifer
What do you want to affect in the included file?
I would like the general facility to plug in any variable
and change it.
highman
08-02-2002, 17:13/05:13PM
harv im not a programmer, but from the sound of it you need to be using .asp or php to do this, i think shtml will provide the ability to use includes but not much else.
harv
10-02-2002, 07:09/07:09AM
Yes I agree that php will do this.
I'm just trying to understand Kristoffer's example.
Kristoffer, I'm not clear about the statement
"The page to display look like this"
Also must both files (i.e the main file
and the included file) have the PHP extension ?
It would be much appreciated if you could just list the
2 (?) files so that I can copy and run them.
Thanks
Harvey
crifer
10-02-2002, 09:28/09:28AM
Let's see if i can make i more clear
You can name the file whatever you want, as long as php find the file you don't even need a extention to the file. You could name it "this_is_not_a_file" and php still would parse it. But you need to name the document that you are going to display in the browser with the .php extention. I named the include file with the .php extention is just to make sure that php really will read it and parse the code.
I made the example on the fly, I can write you a real one if you want to, just ask. Maybe I didn't explain the page to display so good. The first <? ?> is like <script> is for javascript, you can also put the <? ?> in the html code as well, just like javascript. When you name a document with the .php extention you tell the server that this document contain ssi and php will parse the document. Then it will find the <? ?> tags and read and execute the code and send the finished document to you.
So according to the example below you first make a variable with the name $myname = "crifer"; php don't care about the html code and find the next "area" to parse, the include command. When php find the include command php know that it need a pointer that point to that name of the file. If the file exist php fill parse and display that file.
So if the include file contain a variable with the name $myname the name crifer will take that place.
--------------------
The page to display look like this:
<?php
$myname = "crifer";
?>
<html>
<head>
</head>
<body>
<? include("this_is_not_a_file"); ?>
</body>
</html>
harv
10-02-2002, 09:57/09:57AM
OK - I've got it now. Thanks
Presumably it is OK for the code
<?php
$myname = "crifer";
?>
to appear before the <html> line (which
is normally the first line in the source).
Harvey
harv
11-02-2002, 18:14/06:14PM
A question for Kristoffer:
You have given an example of a variable
$myname = "crifer";
Presumably you can have any long string of
characters in the variable, even HTML
Suppose you need to put the symbol "
in the string. Is there a way to do it ?
Harvey
crifer
12-02-2002, 08:49/08:49AM
Originally posted by harv
Presumably you can have any long string of
characters in the variable, even HTML
Suppose you need to put the symbol "
in the string. Is there a way to do it ?
Yes, you can put whatever you want in a variable. If you need to put the symbol " in a variable you have to narrow down the " to only a single '
Just ask if there is anything else, good luck
vBulletin® v3.8.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.