SSI #set 变量和#echo 问题
我有一个简单的 .shtml 文件,我在其中声明了一个变量。
<!--#set var="testVar" value="12345" -->
但是当我想使用它打印值时
<!--#echo var="testVar" -->
说
找不到变量“testVar”
有什么问题?我正在使用 IIS 7.5,并且还在 Apache2 上进行了测试,但它也不起作用!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
IIS 不支持您的代码。
IIS 不支持 #set,这就是它响应的原因。 “找不到变量‘testVar’”,因为它从未被创建过。
Windows 服务器和 Apache 服务器具有相同的模块名称 (SSI),并且它们使用相同的语法。但! Apache 服务器支持 #set 和其他命令,如 #if #else 等,而 Windows 服务器不支持。所以混乱就完成了。
有关可在 IIS 中使用的命令列表:
有关 IIS 上的 SSI 的 MSDN 博客
IIS doesn't support your code.
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
这对我来说效果很好:
你的 Apache 配置正确吗?您可能需要打开 mod_include。正确配置后,以下代码应输出日期:
This works fine for me:
Do you have Apache configured correctly? You may need to turn on mod_include. The following code should output the date once configured properly:
我有同样的问题。就我而言,我在主文件中设置一个变量,并尝试在包含的模板中读取它。
解决方案是将
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.我认为你需要在变量前面加上“$”来引用你的变量,如下所示:
I think you need to reference your variable with a '$' in front of it, like so:
尝试,
如果没有,请使用 $testVar 确保您的变量被视为变量。
Try,
If not then, use $testVar to make sure your Variable treated as Variable.