Search code examples
vbscriptasp-classicinclude

Replacing part of text string with a page include in Classic ASP


Not 100% sure if this is possible, but hoping there is a workaround. Several hours of searching bring nothing up. I have a text string written to the page from a Db table. If it contains a specific string, I would like to add a page include - example below does write:

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

into the text, but does not pull the included file content in.

<%=Replace(myQuery("Text"), "123456", "%><!--#include file="mypage.asp"--><% ")%>

Client wants it in the page rather than at the top or bottom of the output which would be so easy (and we already do that) The include has to go in at a specific point in the text.

I would appreciate any help, even if it is to confirm that it is not possible to do this.


Solution

  • Here is the main page:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Test</title>
    </head>
    <body onload="document.getElementById('placeholder').innerText = document.getElementById('alwaysfillme').innerText">
        <p><%=Replace("ABCDEFGHIJKLMNOPQRSTUVWXYZ", "J", "<span id=""placeholder""></span>")%></p>
        <span id="alwaysfillme" style="display:none;"><!--#include file="mypage.asp"--></span>
    </body>
    </html>
    

    And here is what I stuck in "mypage.asp":

    <% response.Write("--123--") %>
    

    When a J is in the text, it displays:

    ABCDEFGHI--123--KLMNOPQRSTUVWXYZ
    

    When no J is in the text, it displays:

    ABCDEFGHIKLMNOPQRSTUVWXYZ