Equivalent to master pages in ASP Classic

Is it possible to create some kind of master page with classic ASP without frames or iframes?

I am wondering if there is a way to include content pages on the main page, such as the main ASP.NET pages . From what I explored, ASP Classic supports the inclusion of other ASP / HTML pages in the page, but the value entered into this includemeans that the function cannot be dynamic.

+3
source share
5 answers

You could just create functions (like a function Header()and a function Footer()) that do nothing but output a set of markup. These functions can also take parameters and are called conditionally. This is not exactly the same as the main page, but it looks like it is doing what you are trying to do. You will have <!--#include file="headerfooter.asp"-->every page, and every page will call Header()and Footer().

Or you can simply use the <!--#include file="header.asp"-->top and <!--#include file="footer.asp"-->bottom of each page. I have seen both approaches.

, , "" , , ASP classic. : ASP.NET , .., ASP Classic script, .

+12

ASP- | . Ive , .

, ( <!--#include file="" -->). - , master.asp. . Sub, , .

master.asp
<!DOCTYPE html>
<html>
    <head>
        <title><% Title() %></title>
    </head>
    <body>
        <% BodyContent() %>
    </body>
</html>
aboutUs.asp
<!--#include file="master.asp" -->

<% Sub Title %> About Us <% End Sub %>

<% Sub BodyContent %>
    <h1>About Us</h1>
    <p>
        We do things!
    </p>
<% End Sub %>

HTML-, aboutUs.asp IIS:

<!DOCTYPE html>
<html>
    <head>
        <title> About Us </title>
    </head>
    <body>

    <h1>About Us</h1>
    <p>
        We do things!
    </p>

    </body>
</html>

:

subtemplate.asp
<div class="innerLogo <% LogoSide() %>">
    <% LogoImg() %>
</div>
template_user.asp
<!--#include file="master.asp" -->

<% Sub Title %> Our Logo <% End Sub %>

<% Sub BodyContent %>

    <!--#include file="subtemplate.asp" -->

    <% Sub LogoSide %> leftside <% End Sub %>

    <% Sub LogoImg %>
        <img src="img/about.png" alt="About" />
    <% End Sub %>

<% End Sub %>

, Sub :

Microsoft VBScript '800a03ea'

/template_user.asp, 9

Sub LogoSide
^

, , , . , . , , DRY.

+6

ASP , #includes , if - then - else - , .

, , , " ".

- , KudzuASP, #include. :

<!-- An HTML Template -->
<html>
<head><title><!--[Replace|PageTitle]-->PageTitle<!--[/Replace]--></title></head>
<body>
<table border="1" cellpadding="4" callspacing="2" width="640">
<tr>
    <td colspan="2"><!--[HeaderContent/]--></td>
</tr>
<tr>
    <td width="160"><!--[LeftColumnContent/]--></td>
    <td><!--[MainContent/]--></td>
</tr>
<tr>
    <td colspan="2"><!--[FooterContent/]--></td>
</tr>
</table>
</body>
</html>

ASP :

<%@ Language=VBScript %>
<!-- #include file="./KudzuASP/_kudzu.asp" -->
<%
Dim PageTitle : PageTitle = "This is a Master Page"

'
' Create the template engine
'
Dim T_ENGINE
Set T_ENGINE = New CTemplateEngine

T_ENGINE.PutValue "PageTemplate", PageTemplate
T_ENGINE.SetHandler "HeaderContent", New CTXHeaderContent
T_ENGINE.SetHandler "LeftColumnContent", New CTXLeftColumnContent
T_ENGINE.SetHandler "MainContent", New CTXMainContent
T_ENGINE.SetHandler "FooterContent", New CTXFooterContent

'
' Custom Tage Handlers
'
Class CTXHeaderContent
    Public Sub HandleTag(vNode)
        vNode.Engine.ContentAppend "Header"
    End Sub
End Class

Class CTXLeftColumnContent
    Public Sub HandleTag(vNode)
        vNode.Engine.ContentAppend "Left<br/>Content"
    End Sub
End Class

Class CTXMainContent
    Public Sub HandleTag(vNode)
        vNode.Engine.ContentAppend "Main<br/>Content"
    End Sub
End Class

Class CTXFooterContent
    Public Sub HandleTag(vNode)
        vNode.Engine.ContentAppend "Footer"
    End Sub
End Class

'
' Evaluate the template
'
T_ENGINE.ParseFile Server.MapPath("./MasterPage.html")
T_ENGINE.EvalTemplate
%>

, ASP ASP . , . , ASP .

, , HTML , , <!--[import/]-->.

UPDATE 2016.01.13: , , : https://github.com/Mumpitz/KudzuASP p >

+3

- ASP, , " " , Subs .

, JavaScript ASP , , ASP VBScript, ASP JavaScript.

master.asp
<!DOCTYPE html>
<html>
    <head>
        <title><% Title() %></title>
    </head>
    <body>
        <% BodyContent() %>
    </body>
</html>
subtemplate.asp
<div class="innerLogo <% LogoSide() %>">
    <% LogoImg() %>
</div>
template_user.asp
<%@ Language= "Javascript" %> 
<!--#include file="master.asp" -->

<% function Title() { %> About Us <% } %>

<% function BodyContent() { %>

    <!--#include file="subtemplate.asp" -->

    <% function LogoSide() { %> leftside <% } %>

    <% function LogoImg() { %>
        <img src="img/about.png" alt="About" />
    <% } %>
<% } %>

! :

<!DOCTYPE html>
<html>
    <head>
        <title> About Us </title>
    </head>
    <body>

    <div class="innerLogo  leftside ">
      <img src="img/about.png" alt="About" />
    </div>

    </body>
</html>

, JavaScript, ECMAScript 3 ASP, , VBScript, Microsoft. - ASP, JavaScript!

+1

Default.asp html, .

<%@ Language="VBScript" %>
    <!DOCTYPE html>
    <html lang="en">
        <head>
             <meta charset="utf-8" />
        </head>
        <body>
            <div id="topNav"> <!--begin top Nav-->
                <ul> 
                    <!--Be sure that all links are like this href="?page=contentPageEx"-->
                    <li><a href="?page=home">Home</a></li> 
                </ul>   
            </div> <!--end top Nav-->

            <div id="content">
                   <%
                        Dim default
                        default= Request.QueryString 
                        If default= "" Then 
                        Server.execute "includes/home.html"
                        Else 
                        Server.execute "includes/" & request("page")  & ".html"
                        end if 
                    %>   
            </div>  


            <div id="botNav"> <!--begin bot Nav-->
                <ul> 
                  <li><a href="?page=home">Home</a></li>   
                </ul>
            </div> <!--end Bot Nav-->

         </body>
</html> 

include html-.

  <!DOCTYPE html>

    <html lang="en">
        <head>
            <meta charset="utf-8" />

            <!--Search engines use this title ect...-->
            <title>Hello SEO! This is a content page!</title>
            <!--Can be styled independently-->
            <style>
              p {
                    color: #0094ff;   
                }  
            </style>
        </head>
        <body>
         <p>Hello World!</p>   
        </body>
    </html> 
0

Source: https://habr.com/ru/post/1745505/


All Articles