The ExpandTemplate method is used to expand template pages that contain FoxPro expressions using Active Server like syntax using < % expression() % > and < % Command % > syntax inside of HTML documents. The method generates a fully self contained HTML page/HTTP output which includes an HTTP header.

ExpandTemplate can expand files from disk based on a path or from a string.

FoxPro Expressions:

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

Script Blocks:

<label>Numbers entered:</label>

<div class="result">
lcOutput = ""
FOR x = 1 to 10
   lcOutput = lcOutput + TRANS(x) + " "

Expressions are evaluated in sequence from top to bottom of the document.

Script Blocks are self contained Procedures

Please be aware that script blocks (rather inside of templates are executed as self-contained procedures, meaning any variables you declare inside of the script block won't be visible outside of the script block. You also can't use structure statements that wrap HTML or other expressions.

Keep script blocks to a minimum, they are expensive to process while expressions are fast. If you need lots of script blocks or need more sophisticated structured commands you can use wwPageResponse::ExpandScript() instead which offers scripting converted to full blown FoxPro PRG files.

o.ExpandTemplate(tcPageName, tcContentType, tlTemplateString, tlReturnAsString)


The physical filename to merge. If omitted the Request.PhysicalPath() is assumed.

If tlTemplateString is .t. this value is the Text to merge rather than a filename.

If tlTemplateString is .F. you can also specify ~ to specify the Application Virtual Root folder:


Optional - The content type of the template output. text/html

Optional - If .t. specifies that the first parameter is the text of the template instead of a filename. .F.

Optional - if .T. returns the output as a string instead of writing it into the Response stream.


Expressions are not evaluated recursively - have an expression that returns another expression this retrieved expression is not evaluated.

See also:

Class wwPageResponse

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