IT tutorials
 
Graphics
 

Dreamweaver CS5 : Establishing Optional Regions (part 2) - Evaluating template expressions

12/6/2011 5:17:28 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

3. Evaluating template expressions

With optional regions, template expressions are either set explicitly or evaluated to true or false. Template expressions can also be used throughout the template to great effect. Here is a short list of what's possible with template expressions:

  • Alternate the background color of a row contained in a repeating region.

  • Automatically number each row in a repeating region.

  • List the total number of rows in a repeating region.

  • Show an optional region if a certain number of rows are used, or another region if that number of rows is exceeded.

  • Create sequential navigation links, allowing users to page to the next — or previous — document in a series.

  • Compute values displayed in a table, displaying items such as basic cost, tax, shipping, and total.

  • Display particular content depending on the position of the row — first, second, second-to-last, or last, for example — in the repeating region.

Two types of template expressions exist: template expression statements and inline template expressions. Template expression statements take the form of a specialized HTML comment, like this:

<!-- TemplateExpr expr="fileExt"-->

Template expression statements are coded by hand. Inline template expressions are surrounded by parentheses and double @ signs, like this:

@@(fileExt)@@

Inline template expressions can only be entered by hand, but they are very flexible. You can insert an inline template expression as an attribute into any of Dreamweaver's text field interfaces, such as the Link field of the text Property inspector or the Bg (Background Color) field of the row Property inspector. Template expressions not entered as attributes appear as Invisible Elements with a double @ sign symbol, as shown in Figure 3. Template expression statements appear with a script icon.

Although you can enter an inline template expression in Code view without a problem, you cannot enter one on the page in Design view.


3.1. Template expression language and object model

Template expressions are written in their own language, which uses a subset of JavaScript operators and its own object model. The syntax of template expressions closely resembles that of JavaScript, and both use a similar dot notation to refer to the properties of a specific object. Similar to JavaScript, Dreamweaver template expressions also have their own object model, although the object model for template expressions is much more limited in scope.

The elements supported by Dreamweaver template expressions are detailed in Table 1.

Figure 3. Template expressions can either be entered as statements or inline code.

Table 1. Template Expression Features and Operators
LiteralsSyntaxExample
Numeric LiteralDouble-quoted numbers"123"
String LiteralDouble-quoted string"Chapter"
Boolean Literalstrue/falsetrue
String Concatenationstring1 + string2"Number of rows: " + _numRows
Ternary Operator  
Conditionalcondition ? resultA : resultB(_index & 1) ? #FFFFFF : #CCCCCC
Logical Operators  
Logical NOT!operand!mainLogoRegion
Logical ANDoperand1 && operand2onSale && nowFeatured
Logical ORoperand1 || operand2onSale || nowFeatured
Arithmetic Operators  
Additionoperand1 + operand2_numRows + 1
Subtractionoperand1 – operand2_index – 1
Multiplicationoperand1 * operand2basePrice * taxBase
Divisionoperand1 / operand2numSold / quantityShown
Modulooperand1 % operand2_index % 2
Comparison Operators  
Less Thanoperand1 < operand2inStock < numSold
Greater Thanoperand1 > operand2numSold > numShipped
Less Than or Equaloperand1 <= operand2_index <= _numRows
Greater Than or Equaloperand1 >=operand2_numRows >= pageLimit
Equaloperand1 == operand2_index == 10
Not Equaloperand1 != operand2_numRows != 1
Bitwise Operators  
Bitwise NOT~erand~4
Bitwise ANDoperand1 & operand2_index & 1
Bitwise ORoperand1 | operand24 | 8
Bitwise XORoperand1 ^ operand22 ^ 4
Bitwise Signed Right Shiftoperand1 >>8 >> 1
Bitwise Left Shiftoperand1 <<1 << 0

The template expressions document model is made up of two primary objects: _document and _repeat. The document object contains all the template variables found on the page. For example, if you create an optional region with the name altImageRegion, you can refer to it in a document expression with the following statement:

<!-- TemplateBeginIf cond="_document.altImageRegion"-->

However, the _document prefix is implicit, and the same statement can be written like this:

<!-- TemplateBeginIf cond="altImageRegion"-->

As you may suspect, the _repeat object refers to a repeating region. The _repeat object has a number of very useful properties, as shown in Table 2.

Table 2. _repeat Object Properties
PropertyDescription
_indexReturns the index number of the current entry. The _index property is zero-based, so for the first entry of a repeating region, _index equals zero.
_numRowsReturns the total number of entries in a repeating region.
_isFirstReturns True if the current entry is the first entry of a repeating region, False otherwise.
_isLastReturns True if the current entry is the last entry of a repeating region, False otherwise.
_prevRecordReturns the _repeat object for the entry before the current entry. For example, if _index = 2, then _prevRecord._index = 1. If _prevRecord is used in the first entry, an error occurs.
_nextRecordReturns the _repeat object for the entry after the current entry. For example, if _index = 2, then _nextRecord._index = 3.
_parentReturns the _repeat object for a repeating region enclosing the current repeating region. For example, use _parent._numRows to find the total number of rows of the outer repeating region.

The _repeat object is also implicit, and it is not necessary to reference it specifically in a template expression.

3.2. Multiple-if template expressions

Certain template expressions cannot be handled by referencing a single condition — "If A is true, show B" does not cover every possible circumstance. What if you wanted to test against multiple conditions and provide multiple results? Can Dreamweaver handle something like "If A is true, show B; but if C is true, show D — and if neither of them is true, show E"? With the help of multiple-if expressions, you bet it can.

With a multiple-if template expression, you can test for any number of conditions and act accordingly. Multiple-if expressions use two different template expressions: one to close the entire expression and another one for each separate case. Here is an example:

<!-- TemplateBeginMultipleIf-->
<!-- checks value of template parameter SKU and shows the desired image-->
<!-- TemplateBeginIfClause cond = "SKU == 101">
<img src = "/images/ring101.tif" width="125" height="125">
<!-- TemplateEndIfClause-->

<!-- TemplateBeginIfClause cond = "SKU == 102">
<img src = "/images/bracelet102.gif" width="125" height="125">
<!-- TemplateEndIfClause-->

<!-- TemplateBeginIfClause cond = "SKU == 103">
<img src = "/images/necklace103.gif" width="125" height="125">
<!-- TemplateEndIfClause-->

//default display if none of the other conditions are met
<!-- TemplateBeginIfClause cond = "SKU != 103">
<img src = "/images/spacer.gif" width="125" height="125">
<!-- TemplateEndIfClause-->
<!-- TemplateEndMultipleIf-->

In this code, if none of the conditions are met, a blank spacer image is displayed. As with other template expressions, multiple-if expressions must be coded by hand.

 
Others
 
- Dreamweaver CS5 : Establishing Optional Regions (part 1)
- Adobe Photoshop CS5 : The Fastest Way to Resize Brushes Ever (Plus, You Can Change Their Hardness, Too)
- Adobe Photoshop CS5 : Fixing Dark Eye Sockets
- Adobe After Effects CS5 : Creating a Basic Animation Using Effects and Presets - Creating a new composition
- Adobe After Effects CS5 : Importing footage using Adobe Bridge
- Adobe Fireworks CS5 : Repairing areas with the Rubber Stamp tool
- CorelDraw 10 : Hyperlinks and Bookmarks (part 2) - Creating bookmarks and links
- CorelDraw 10 : Hyperlinks and Bookmarks (part 1)
- Adobe Flash Professional CS5 : Free Transform Commands and Options
- Adobe Flash Professional CS5 : Applying Modify Shape Menu Commands
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us