Request a parameter for the server behavior – Adobe Dreamweaver CS3 User Manual
Page 604
DREAMWEAVER CS3
User Guide
597
Using the loop directive’s _length and _index variables
The loop directive includes two built-in variables that you can use for embedded
if
conditions. The variables are:
_length
and
_index
. The
_length
variable evaluates to the length of the arrays processed by the loop directive,
while the
_index
variable evaluates to the current index of the loop directive. To ensure that the variables are only
recognized as directives, and not as actual parameters to be passed into the loop, do not enclose either variable in
@@
s.
An example of using built-in variables is to apply them to the
import
attribute of the page directive. The
import
attribute requires comma separation of packages. If the
loop
directive extends around the entire
import
attribute,
you would only output the attribute name
import=
on the first iteration of the loop—this includes the closing double
quote (")—and not output a comma on the last iteration of the loop. Using the built-in variable, you can express this
as follows:
<@loop (@@Import@@)@>
<@ if(_index == 0)@>import="
<@endif@>@@Import@@<@if (_index == _length-1)@>"<@else@>,
<@ endif @>
<@endloop@>
Request a parameter for the server behavior
Server behaviors often require that the page designer supply a parameter value. This value must be inserted before
the server behavior’s code is inserted into the page.
You create the dialog box by defining the designer-supplied parameters in the code. Then you generate a dialog box
for the server behavior, which prompts the page designer for a parameter value.
Note: A parameter is added to your code block without your intervention if you specify that your code should be inserted
relative to a specific tag chosen by the page designer (that is, you chose Relative to a Specific Tag in the Insert Code pop-up
menu). The parameter adds a tag menu to the behavior’s dialog box to let the page designer select a tag.
Define the parameter in the server behavior code
1
Enter a parameter marker in the code where you want to insert the supplied parameter value. The parameter has
the following syntax:
@@parameterName@@
2
Enclose the
formParam
string in parameter markers (
@@
):
<% Session(“lang_pref”) = Request.Form(“@@formParam@@”); %>
For example, if the server behavior contains the following code block:
<% Session(“lang_pref”) = Request.Form(“Form_Object_Name”); %>
To require the page designer supply the value of
Form_Object_Name
, enclose the string in parameter markers (
@@
):
<% Session(“lang_pref”) = Request.Form(“@@Form_Object_Name@@”); %>
You can also highlight the string and click the Insert Parameter In Code Block button. Enter a parameter name and
click OK. Dreamweaver replaces every instance of the highlighted string with the specified parameter name enclosed
in parameter markers.
September 4, 2007