About code blocks

About code blocks

The code blocks you create in the Server Behavior Builder are encapsulated in a server behavior that appears in the Server Behaviors panel. The code can be any valid runtime code for the specified server model. For example, if you choose ColdFusion as the document type for your custom server behavior, then the code you write must be valid ColdFusion code that runs on a ColdFusion application server.

Related topics

  • Coding guidelines

Code blocks

You can create the code blocks either directly within the Server Behavior Builder, or you can copy and paste the code from other sources. Each code block you create in the Server Behavior Builder must be a single tag or script block. If you need to insert multiple tag blocks, split them into separate code blocks.

For more information, see Using the Server Behavior Builder

Runtime Parameters

You can include parameters in your runtime code and let the page designer supply the parameter values. To do so, enter parameter markers in the code, as follows:

@@parameterName@@

For more information, see Using parameters in server behaviors.

Conditions and repeating elements in code blocks

If you want the code block, or a portion of a code block, to be executed only if a certain condition or conditions apply, use the following syntax:

<@ if (expression1) @>
   code block1
[<@ elseif (expression2) @>
   code block2]*
[<@ else @>
   code block3]
<@ endif @>

The square brackets ([ ]) denote optional code and the asterisk (*) denotes zero or more instances. The condition expression is any valid JavaScript condition expression, and may contain server behavior parameters.

If you want the code block, or a portion of a code block, to be repeated a number of times, use the following syntax:

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

The loop directive takes a comma-separated list of parameter arrays as arguments. The repeating text will be 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.

For general information on coding, see Coding guidelines.

Related topics

  • Making code blocks conditional
  • Repeating code blocks

Code block positioning within web pages

When you create code blocks using the Server Behavior Builder (see Using the Server Behavior Builder for more information), you must specify where to insert them in the page’s HTML code. You do this using the Server Behavior Builder dialog box’s Insert Code and Relative Position pop-up menus, which let you select where to insert the code block within the document, and then specify a position relative to another tag in the page.

For example, if you insert a code block above the opening <html> tag, you must then specify the code blocks position relative to other tags, scripts, and server behaviors in that section of the page’s HTML code. Typical examples include positioning a behavior either before or after any recordset queries that might also exist in the page code above the opening <html> tag.

When you select a positioning option from the Insert Code pop-up menu, the options available in the Relative Position pop-up menu change to provide relevant options for that part of the page. For example, if you select Above the <html> Tag in the Insert Code pop-up menu, then the positioning options available in the Relative Position pop-up menu reflect choices relevant for that part of the page.

The code block insert options, and the relative positioning options available for each, are shown in the table below.

Insert Code options

Relative position options

Above the <html> Tag

  • At the beginning of the file
  • Just before the recordsets
  • Just after the recordsets
  • Just above the <html> tag
  • Custom position

Below the </html> Tag

  • Before the end of the file
  • Before the recordset close
  • After the recordset close
  • After the </html> tag
  • Custom position

Relative to a Specific Tag

Select a tag from the Tag pop-up menu, and then choose from the tag positioning options.

Relative to the Selection

Before the selection

After the selection

Replace the selection

Wrap the selection

If you want to specify a custom position, you must assign a weight to the code block. Use the Custom Position option when you need to insert more than one code block in a particular order. For example, if you want to insert an ordered series of three code blocks after the code blocks that open recordsets, you would enter a weight of 60 for the first block, 65 for the second, and 70 for the third.

By default, Dreamweaver assigns a weight of 50 to all recordset-opening code blocks inserted above the <html> tag. If the weight of two or more blocks match, Dreamweaver randomly sets the order among the blocks.

Related topics

  • About code blocks
  • Positioning code blocks


Getting Started with Dreamweaver
Dreamweaver Basics
Working with Dreamweaver Sites
Laying Out Pages
Adding Content to Pages
Working with Page Code
Preparing to Build Dynamic Sites
Making Pages Dynamic
Defining Sources of Dynamic Content
Developing Applications Rapidly
 
ASPTreeView.com
 
Evaluation has ¶»ѕѕКЧПРexpired.
Info...