wwPageResponse::ExpandScript

The ExpandScript method method is used to expand script pages that contain FoxPro expressions and Code blocks using Active Server like syntax. The method generates a fully self contained HTML page/HTTP output which includes an HTTP header.

This class uses the wwScripting class to parse expression blocks and codeblocks. ExpandScript() behavior can be called explicitly or is available through generic script processing in the wwScriptMaps process handler which can be mapped for any extension in your server's Process method.

ExpandScript() call syntax Examples:

Response.ExpandScript()                     && Request.PhysicalPath() is used
Response.ExpandScript("~\scriptdemo.wcs")   && Virtual Path as base
Response.ExpandScript(Config.cHtmlPagePath + "scriptDemo.wcs")

Example HTML markup:

<div class="customer-list">
    <%
       SELECT * from Customers INTO CURSOR TQuery
       SCAN
    %>
        <div class="customer-item">
            <div class="company-text"><%= TQuery.Company %></div>
            <div class="company-date"><%= TQuery.Entered %></div>
        </div>
        
    <% ENDSCAN %>
</div>
o.ExpandScript(tcPageName, tnMode, tvContentType, tlReturnAsString)

Return Value

nothing

Parameters

tcPageName
Optional - Name of the page from disk to expand. Optionally, this can be the actual string of the script to evaluate. If not provided Request.GetPhysicalPath() is used.

Also supports ~ for referencing the Application Virtual root path:
Response.ExpandScript("~\Customers\Customer.wwd")

tnMode
Optional - Determines the compilation mode for scripts. Default Mode is 1. For more info see wwServer::nScriptMode.

  • Dynamic Compilation
  • Precompiled FXP files
  • Interpreted with ExecScript

tvContentType
Optional - Either a wwHTTPHeader object or a content type string. "none" write no header.

tlReturnAsString
Optional - return the output from rendering as a string and don't write out to the Response stream. No HTTP header is generated in this mode.

Remarks

The Server.lDebugMode flag determines the level of error information that is displayed. With DebugMode .T. the source error is displayed in the page and a PRG file is generated that you can examine in the same directory as the script file. With DebugMode .F. the PRG file is not generated and wwScripting will not be able to retrieve or display the location of the error only the error message.

Example

Expression Examples:

<%= DateTime() %>
<%= lcVar %>
<%= TQuery.FieldName %>
<%= MyFunction() %>

Code Block Examples:

<div class="container">
	<%
    	lcOutput = ""
	    for x = 1 to 5
    	    lcOutput = lcOutput + TRANS(x) + "<br>"
	    endfor
    %>
	<div>
		<%= lcOutput %>
	</div>


	<%
	    SELECT Company from TT_CUST INTO CURSOR TQuery 
    	SCAN
	%>
	<div class="company-item">
		<label>Company:</label>
		<div class="company-text"><%= Company %></div>	
    </div>

	<% ENDSCAN %>
</div>

To exit a script issue RETURN as part of a script block:

<% 
   IF llCanceled 
      RETURN && Exit script
   ENDIF
%>

Script pages have access to a special wwScriptingHttpResponse object which provides the ability to write output into the HTTP stream using Response. methods. From within script code you can add headers, cookies and otherwise manipulate the Response.

<%
   lcOutput = "New Value"
   Response.Write(lcOutput)
%>

<%
   Response.AppendHeader("Expires","-1")
   Response.AppendHeader("Refresh","1;url=http://www.west-wind.com/")
   Response.AddCookie("SomeCookie","Some Value")
   Response.AddCookie("MyCookie","My Cookie Value","/",Date() + 10)
%>

Overloads:


See also:

Class wwResponse | wwResponse::ContentTypeHeader | wwResponse::ExpandTemplate

© West Wind Technologies, 1996-2024 • Updated: 11/01/18
Comment or report problem with topic