David Weng
David Weng

Reputation: 4245

SSI #set variable and #echo issue

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

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

But when I want to print the value using

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

it says

Variable 'testVar' cannot be found

What's the problem? I'm using IIS 7.5 and I also tested in on Apache2 but it's not working either!

Upvotes: 6

Views: 10046

Answers (5)

frank jelstrup
frank jelstrup

Reputation: 21

IIS doesn't support your code.

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

IIS doesn't support #set that is why it responds. "Variable 'testVar' cannot be found", because it has never been created.

Windows server and Apache server has the same module name (SSI) and they use the same syntax. BUT! Apache server supports #set and other commands like #if #else etc which windows server doesn't. So the confusion is complete.

For a list of commands you can use in IIS: MSDN blog about SSI on IIS

Upvotes: 2

trey-jones
trey-jones

Reputation: 3437

I had the same issue. In my case, I was setting a variable in the main file, and trying to read it in an included template.

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

Upvotes: 1

Rahul Kumar
Rahul Kumar

Reputation: 77

Try,

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

If not then, use $testVar to make sure your Variable treated as Variable.

Upvotes: 0

Craig Myles
Craig Myles

Reputation: 5464

This works fine for me:

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

Do you have Apache configured correctly? You may need to turn on mod_include. The following code should output the date once configured properly:

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

Upvotes: 1

Bill
Bill

Reputation: 9

I think you need to reference your variable with a '$' in front of it, like so:

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

Upvotes: 0

Related Questions