开发者

VBscript pass parameters to included file

Ok, I'm new to the asp/vbscript world. I am working at a new company and am trying to reproduce a script I use on almost all projects when developing under php.I have two functions one called showHeader and one called showFooter. These functions both get arguments passed to them and those arguments need to be displayed in the included file. For example in php my showHeader function is like so

<?php
showHeader($page,$title,$passedCSS,$desc,$keywords) {
include("header.php");
}
?>

Now in the includ开发者_运维问答e file i can echo out the contents of any of those arguments simply by calling echo $var and i get the contents. Is this possible with vbscript. I'm having no luck what so ever.


@projectxmatt: You could do something like --

In header.asp:

<%
Sub showHeader(page, title, passedCSS, desc, keywords)
%>
<!-- some HTML code here -->
<title><%=page %></title>
<!-- more HTML code here -->
<%
End Sub
%>

In somefile.asp:

<!-- #include file="header.asp" -->
<% showHeader "value-for-page", "My Page Title", "", "", "" %>

With ASP you have to specify all the variables you have in your Sub or Function, they can't be left out or assigned with a default as in PHP if none was passed to the function (e.g. function showHeader(title = 'Default Value'))


Ok here is what i did

global.asp


   <%@LANGUAGE="VBSCRIPT"%>
<%  
    Sub showHeader(page,title,passedCSS,desc,keywords)
%>
        <!---#include file="header.asp"--->
<%
    end Sub

    Sub showFooter(passedJS)
%>
        <!---#include file="footer.asp"--->
<%
    end Sub
%>

Then in header.asp and footer.asp I passed in the vars just using <%=varname%>

Then in the main.asp my code was as follows.

<!---#include file="global.asp"--->
<% showHeader "Home","Test Page","test.css","Description","keywords" %>
        <section>
        </section>

        <aside>
        </aside>

        <section>
            <h2></h2>
            <ul>
                <li><article></article></li>
                <li><article></article></li>                
            </ul>
        </section>

        <section>
            <div></div>
            <div></div>
            <div></div>
        </section>
<% showFooter "testjs.js" %>

And everything works great.


Response.Write would be another solution you could use to write output in classic ASP.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜