But when I...">

SSI variable #set and #echo

I have a simple .shtml file that I declared a variable in it.

 <!--#set var="testVar" value="12345" --> 

But when I want to print the value using

 <!--#echo var="testVar" --> 

it says

Unable to find the variable 'testVar'

What is the problem? I am using IIS 7.5 and I also tested it on Apache2, but it does not work either!

+6
server-side-includes
source share
5 answers

This works fine for me:

 <!--#set var="testVar" value="12345" --> <!--#echo var="testVar" --> 

Is Apache configured correctly? You may need to enable mod_include . The following code should display the date after the proper configuration:

 <!--#echo var="DATE_LOCAL" --> 
+1
source share

I had the same problem. In my case, I set the variable in the main file and tried to read it in the included template.

The solution was to put <!--#set after the <!DOCTYPE declaration.

+1
source share

IIS does not support your code.

 <!--#set var="testVar" value="12345" --> 

IIS does not support #set, so it responds. "Variable" testVar "could not be found" because it was never created.

The Windows server and Apache server have the same module name (SSI), and they use the same syntax. BUT! The Apache server supports #set and other commands, such as #if #else, etc., which the Windows server does not have. So the confusion is complete.

List of Commands You Can Use in IIS: MSDN Blog about SSI in IIS

+1
source share

I think you need to reference your variable with the "$" in front of it, for example:

 <!--#echo var="$testVar" --> 
0
source share

Try

 <!--#echo encoding="entity" var="testVar" --> 

If not, use $ testVar to verify that the variable is treated as a variable.

0
source share

All Articles