SSI #set 变量和#echo 问题

发布于 2024-09-30 10:12:21 字数 310 浏览 1 评论 0原文

我有一个简单的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

凡尘雨 2024-10-07 10:12:21

IIS 不支持您的代码。

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

IIS 不支持 #set,这就是它响应的原因。 “找不到变量‘testVar’”,因为它从未被创建过。

Windows 服务器和 Apache 服务器具有相同的模块名称 (SSI),并且它们使用相同的语法。但! Apache 服务器支持 #set 和其他命令,如 #if #else 等,而 Windows 服务器不支持。所以混乱就完成了。

有关可在 IIS 中使用的命令列表:
有关 IIS 上的 SSI 的 MSDN 博客

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

妥活 2024-10-07 10:12:21

这对我来说效果很好:

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

你的 Apache 配置正确吗?您可能需要打开 mod_include。正确配置后,以下代码应输出日期:

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

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" -->
杀お生予夺 2024-10-07 10:12:21

我有同样的问题。就我而言,我在主文件中设置一个变量,并尝试在包含的模板中读取它。

解决方案是将

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.

不疑不惑不回忆 2024-10-07 10:12:21

我认为你需要在变量前面加上“$”来引用你的变量,如下所示:

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

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

<!--#echo var="$testVar" -->
澉约 2024-10-07 10:12:21

尝试,

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

如果没有,请使用 $testVar 确保您的变量被视为变量。

Try,

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文