I have a simple .shtml
file that I h开发者_开发技巧ave 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!
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" -->
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.
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
I think you need to reference your variable with a '$' in front of it, like so:
<!--#echo var="$testVar" -->
Try,
<!--#echo encoding="entity" var="testVar" -->
If not then, use $testVar to make sure your Variable treated as Variable.
精彩评论