如果页面是默认那么包括如果没有则默认 [英] if page is default then include if not default then

查看:190
本文介绍了如果页面是默认那么包括如果没有则默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过类似的问题,但没有一个似乎为我工作。

我有一个asp网站,我认为经典的(甚至不知道经典和净之差),与所有扩展名为ASP几页,和一些HTML包括,这些是一个滑块的一方,我只想展示当网页(Default.asp的),如果不是默认,然后一个div添加到标记。

我知道下面是错误的,但只是为了更好地解释我的需要。

 <%
如果页面==的Default.asp
包括文件=slider.html
如果页面!=的Default.asp
< D​​IV CLASS =间隔顶>< / DIV>
%GT;


解决方案

像许多在ASP-经典地在你的predecessors,什么你想是有条件的包含,而你碰到的问题是即传统的ASP没有做条件包括。 (之所以是,的#include 指令在页面上的任何脚本解析之前长柄)。

有涉及执行或各种解决方法等危险,在最​​错手命令;搜索 ASP条件包括,你会发现更多的比你讨价还价对于。然而,在你的情况,它可能是简单包住的,你可以通过电话或不是一个子程序滑块显示。

Slider.html:

<%
子DisplaySlider()
    code,显示滑块(可能是JavaScript的,我猜?)
    %GT;
    <脚本...>
    < / SCRIPT>
    <%
结束小组
%GT;

其他网页:

<! - #包括虚拟=/ slider.html - >
<%
脚本名称= Request.ServerVariables(SCRIPT_NAME)
如果INSTR(脚本名称的default.asp)> 0,则
    DisplaySlider
其他
    的Response.Write< D​​IV CLASS ='间隔顶'>< / DIV>中
万一
%GT;

I've read similar questions, but none seems working for me.

I have an asp site, i think classic (don't even know difference between classic and net), with few pages all with asp extension, and some html includes, one of these being a slider which I want to only display when in homepage (default.asp), and if not default then add a div to the markup.

I know the following is wrong, but just to better explain my need.

<%
if page == default.asp
include file="slider.html"
if page != default.asp
<div class="spacer-top"></div>
%>

解决方案

Like many of your predecessors in ASP-classic-land, what you're wanting is conditional includes, and the problem you're bumping into is that classic ASP doesn't do conditional includes. (The reason why is that the #include directive is handled long before any script on the page is parsed.)

There are various workarounds involving Execute or other dangerous-in-the-wrong-hands commands; search for "asp conditional include" and you'll find more than you were bargaining for. However, in your case, it might be simpler to encase the slider display in a subroutine that you can call or not.

Slider.html:

<%
Sub DisplaySlider()
    'code to display the slider (probably JavaScript, I'm guessing?)
    %>
    <script ...>
    </script>
    <%
End Sub
%>

Other pages:

<!-- #include virtual="/slider.html" -->
<%
scriptname = Request.ServerVariables("Script_Name")
If InStr(scriptname, "default.asp") > 0 Then
    DisplaySlider
Else
    Response.Write "<div class='spacer-top'></div>"
End If
%>

这篇关于如果页面是默认那么包括如果没有则默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆