wwResponse::ExpandTemplate

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

The template syntax allowed is simple and looks as follows:

<%= Version() %>
<%= Table.FieldName %>
<%= MyUDF() %>
<%= PrivateVar %>
<%= Class.Property %>

or

<%
   Code Block (any valid procedural FoxPro code)
%>

Note that code blocks are self contained and cannot span multiple block statements. You can't use <% if .T. %> and <%= endif %> in separate blocks to conditionally include text in between. To use this behavior you can to use ExpandScript().

Expressions are expanded prior to sending the document back to the client, so expressions are valid anywhere inside of the HTML document including in HTML field values and HREF links etc.

o.ExpandTemplate(lcPageName, lcContentType, llTemplateString, llReturnAsString)

Return Value

"" or HTML string if llNoOutput is .T.

Parameters

lcPageName
Fully qualified filename of the template to expand from disk. Optionally, this may be a string containing the actual script if the llTemplateString parameter is set to .T.

lvContentType

  • Optional* - Either an wwHTTPHeader object or content type string. See wwHTTPHeader class for info.

llTemplateString Optional - If passed .T. it indicates that lcPageName was passed as the actual template string, rather than the filename.

llReturnAsString

  • Optional* - if .T. output is returned to string and no HTTP stream output is created

Remarks

Since embedded code blocks (ie. more than one line of code using <% %>) are dynamically evaluated through macro expansion you'll want to keep the use of code blocks to a minimum for speed reasons. If you use excessive functions in your pages I would highly recommend you build a custom Processing routine as a UDF instead of building the code into an HTML page. Custom code is much easier to debug and maintain and also runs a lot faster since no on the fly evaluation takes place.

Code blocks are self contained and do not support structured commands (IF, DO, WHILE etc.) that span across multiple code blocks. Each block is individually processed and thus can't relate to another code block. IOW, there's no structured command spanning. If you want that behavior please use ExpandScript()wwResponse::ExpandTemplate instead.

Example

Response.ExpandTemplate(THIS.cHTMLPagePath + "node.wc")

See also:

Class wwResponse | wwResponse::ExpandScript | wwResponse::ExpandTemplateToString

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