wwResponse::ExpandScript
about 2 minutes to read

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.

Expression Examples:

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

Code Block Examples:

html
<% lcOutput = "" for x = 1 to 5 lcOutput = lcOutput + TRANS(x) + "<br>" endfor Response.Write(lcOutput) %> <% SELECT Company from TT_CUST INTO CURSOR TQuery SCAN %> Company: <%= Company %><br /> <% ENDSCAN %>

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.

o.ExpandScript(tcPageName, tnMode,
               tvContentType, tlRenderAsString)

Return Value

nothing unless tlRenderAsString is .T. in which case the raw HTML is returned (without HTTP headers)

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.

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.

tlRenderAsString
Optional - If .T. returns output as string rather than rendering into Response stream. No HTTP headers are returned just the raw rendered script output.

Example

foxpro
Response.ExpandScript() && use PhysicalPath Response.ExpandScript(Request.GetPhysicalPath()) && same as above Response.ExpandScript("~/scriptdemo.wcs") && Web Root relative path

Expression Examples:

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

Code Block Examples:

html
<% lcOutput = "" for x = 1 to 5 lcOutput = lcOutput + TRANS(x) + "<br>" endfor Response.Write(lcOutput) %> <% SELECT Company from TT_CUST INTO CURSOR TQuery SCAN %> Company: <%= Company %><br /> <% ENDSCAN %>

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

html
<% 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.

html
<% 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 | wwResponse::ExpandScriptToString

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