|
APG Script Syntax Reference |
|
See Also: |
Delimits a script block written in the default scripting language.
<%# script block #%>
This element is a block element, meaning the #%> tag must be used to specify the end of the script block.
<%# ... #%> is used to indicate a script block within an APG script. Script blocks are executed by a script engine. For more on script blocks and content blocks, see Writing APG Scripts.
The functionality of script brackets is similar to the <SCRIPT> tag. Both indicate a script block. Script brackets are used more frequently than the <SCRIPT> tag because they are more readable and/or easier to type. Many authors use the <SCRIPT>tag only when using multiple scripting languages.
The <%#... #%> syntax is similar to the <%... %> syntax used (also to denote a script block) within ASP. This similarity brings two advantages:
Code within APG script brackets is executed using the default scripting language. The default scripting language is VBScript, but can be changed using a registry setting or the @LANGUAGE tag.
Below is an example using APG script brackets:
<%# Output.Filename = "hello.htm" #%>
<HTML><BODY>
<%#
Dim i
For i = 1 to 5
#%>
<P>Hello World!</P>
<%# Next #%>
</BODY></HTML>
This script creates the following output file (hello.htm):
<HTML><BODY>
<P>Hello World!</P>
<P>Hello World!</P>
<P>Hello World!</P>
<P>Hello World!</P>
<P>Hello World!</P>
</BODY></HTML>
The <%#... #%> syntax is a shorthand notation, used to make it easier to generate content. With APG script brackets, text content and script can be mixed within a single APG file.
The above example is functionally equivalent to the script file below. The file below does not contain any content blocks.
<%#
Output.Filename = "hello.htm"
Output.Write("<HTML><BODY>" & vbCRLF & "")
Dim i
For i = 1 to 5
Output.Write("" & vbCRLF & "<P>Hello World!</P>" & vbCRLF & "")
Next
Output.Write("" & vbCRLF & "</BODY></HTML>")
#%>
APG script brackets provide a clearer, cleaner, easier to write (and easier to debug!) file. These benefits become more significant as content blocks become more complex. In particular, generating files with ASP script and client-side script is very easy with APG script brackets, and very difficult without them.