wwScripting::MergeText

Provides Template parsing for expression evaluated tempaltes. Unlike script pages, MergeText evaluates pages by parsing each script block individually and executing the code contained in it. Uses EVALUATE for <%= %> expressions and EXECSCRIPT for <% %> blocks.

Note that these pages do not execute as a single PRG file so individual Code blocks cannot see variables from other code blocks unless they are made PUBLIC.

For expression based pages template parsing with MergeText can be significantly faster than the script functions.

DO wwScripting
SET SAFETY OFF

LOCAL loScript as wwScripting
loScript = CREATEOBJECT("wwScripting")

TEXT TO lcHtml NOSHOW
<html>
Hello world <%= DATETIME() %>

Dynamic Text:
<% lcOutput = ""
FOR x = 1 TO 10
	lcOutput = lcOutput + "Message" + TRANSFORM(x) + CHR(13) + CHR(10)
ENDFOR

RETURN lcOutput
%>

ENDTEXT
  
? loScript.MergeText(lcHtml)
o.wwScripting.MergeText(lcText,llIsFile)

Return Value

Merged Text (should always return)

Parameters

lcText
The text to expand with syntax.

lIsFile
If .T. the lcText parameter passed is a filename.

Remarks

Unlike RenderAspScript this method doesn't return complete error information, but rather embeds error expressions into the output as .

Script block parsing uses ExecScript() and so any script block is treated like a self contained function. This means that script blocks cannot see any local variables. Any variables declared on the page must be declared PUBLIC if you want to reuse them in multiple script expressions or blocks.

Example

Some plain text

<doc>
   <value>text</value>
</doc>
for x = 1 to 10
   x++
endfor

More:

DO wwScripting
SET SAFETY OFF

LOCAL loScript as wwScripting
loScript = CREATEOBJECT("wwScripting")

TEXT TO lcHtml NOSHOW
<html>
Hello world <%= DATETIME() %>

Dynamic Text:
<%
lcOutput = ""
FOR x = 1 TO 10
	lcOutput = lcOutput + "Message" + TRANSFORM(x) + CHR(13) + CHR(10)
ENDFOR

RETURN lcOutput
%>

ENDTEXT
  
? loScript.MergeText(lcHtml)

See also:

Class wwScripting

© West Wind Technologies, 1996-2018 • Updated: 01/24/17
Comment or report problem with topic