Repeating code blocks with the loop directive – Adobe Dreamweaver CC 2015 User Manual

Page 606

Advertising
background image

599

Dynamic sites, pages and web forms

Last updated 6/3/2015

Position a code block relative to another tag on the page

1

In the Insert Code pop-up menu, select Relative To A Specific Tag.

2

In the Tag box, enter the tag or select one from the pop-up menu.

If you enter a tag, don’t include the angled brackets (<>).

3

Specify a location relative to the tag by choosing an option in the Relative Position pop-up menu.

Position a code block relative to a tag selected by the page designer

1

In the Insert Code pop-up menu, select Relative To The Selection.

2

Specify a location relative to the selection by choosing an option in the Relative Position pop-up menu.

You can insert your code block just before or just after the selection. You can also replace the selection with your
code block, or you can wrap the code block around the selection.

To wrap the code block around a selection, the selection must consist of an opening and closing tag with nothing in
between, as follows:

<CFIF Day=”Monday”></CFIF>

Insert the opening tag piece of the code block before the selection’s opening tag and the closing tag piece of the code
block after the selection’s closing tag.

Repeating code blocks with the loop directive

To repeat a portion of a code block or the entire code block a number of times, use the following syntax:

<@ loop (@@param1@@,@@param2@@) @> code

block<@ endloop @>

When creating server behaviors, you can use looping constructs to repeat a code block a specified number of times. <@
loop (@@param1@@,@@param2@@,@@param3@@,@@param_n@@) @> code block <@ endloop @>The loop
directive accepts a comma-separated list of parameter arrays as arguments. In this case, parameter array arguments
allow a user to supply multiple values for a single parameter. The repeating text is duplicated n times, where n is the
length of the parameter array arguments. If more than one parameter array argument is specified, all the arrays must
have the same length. On the ith evaluation of the loop, the ith elements of the parameter arrays replace the associated
parameter instances in the code block.

When you create a dialog box for the server behavior, you can add a control to the dialog box that lets the page designer
create parameter arrays. Dreamweaver includes a simple array control that you can use to create dialog boxes. This
control, called Text Field Comma Separated List, is available through the Server Behavior Builder. To create user
interface elements of greater complexity, see the API documentation to create a dialog box with a control to create
arrays (a grid control, for example).

You can nest any number of conditionals or a loop directive within a conditional directive. For example, you can specify
that if an expression is true to execute a loop.

The following example shows how such repeating code blocks can be used to create server behaviors (the example is a
ColdFusion behavior used to access a stored procedure):

<@ loop (@@param1@@,@@param2@@,@@param3@@,@@param_n@@) @> code block

<@ endloop @>

Advertising
This manual is related to the following products: