Simple Pound Sign Delimiters: # #
Hello #user.name#. Welcome to my web application.
Hello john. Welcome to my web application.
Inside of view files, code that appears within pound delimiters (# #) signals a script variable, expression, function or statement so that #user.name# outputs the current value of user.name.
Similarly, you can output the current date and time by using the prototype Date object, as in the following example.
The current date and time are #Date()#.
You can use a similar technique to dynamically assign values to attributes within your view file. For example, to display a HTML block only to "John", you can use pound delimiters within the ws:htmlblock tag as in the follow example.
If the expression within the pound delimiters resolves to TRUE, then the HTML block will be displayed, if it resolves to FALSE, it will not displayed.
HTML Comment Delimiters: <!--# #-->
Oftentimes you will want to perform some operation in script and then output the result at some point within your view. In these cases, execute the operation within HTML comment delimiters (<!--# #-->) and then use pound delimiters (# #) to output the result of the operation later in the view.
var d = Date();
d = d.getYear();
d = d - 1776;
It has been #d# years since 1776.
It has been 225 years since 1776.
Note that HTML comment delimiters are used to prevent the final expression, d = d - 1776;, from being output to the view. If pound sign delimiters alone had been used, the value of d would have been output to the view twice, once by the expression d = d - 1776; and again by #d#.
Placement of script in a view
The placement of a script within a .view file depends on the sort of data that the script is designed to access.
If your script includes a reference to the record object, then place your script after the the <ws:dataregion> tag, since the values of the record object are defined only within or after the dataregion.
If you want your script to run before the body of the view is rendered, such as when your script contains conditional redirects to other pages, place your delimited script within the head tags of your view.
var strFile = request.getParameter("TopicID");
response.throwRedirect("http://" + web.name + "." + web.domain
Otherwise, place your script after the opening body tag and before the opening ws:dataregion tag.
var szgh = request.getParameter("_mode", "");
References to the record object should appear after the ws:dataregion tag, and that data region must contain a ws:field tag for the referenced field.
To embed DataWeb Script in client-side script that's running in a view, put the script in substitution syntax within a
CData tag, as follows: