You can create template parameters manually in the code of the template file, but template parameters are also created automatically when you create an optional region as described above. In any case, all template parameters must be written in the head of the document and must follow the syntax shown below (replace <custom> with customized values).
<!-- TemplateParam name="<custom>" type="<custom>" value="<custom>" -->
When you create an optional region using the method described above, the template parameter is written specifically as follows:
<!-- TemplateParam name="<custom>" type="boolean" value="true" -->
While in the template file, you can create an optional region that uses a template parameter by using the Advanced tab of the New Optional Region dialog box:
- Use Parameter: You can create an optional region that uses a pre-existing template parameter IF the template parameter is a boolean type with a value of either true or false. Any parameters that meet that specification will be available in this pop-up menu.
- Enter Expression: Essentially, once you have created a template parameter, the parameter can be used as would any other parameter in JavaScript. In fact, template expressions are based on JavaScript coding rules, so the syntax is identical to JavaScript coding. You can use mathematical functions to add, subtract, multiply or divide parameters to added complexity.
You can also create an optional region that uses a template parameter directly within the code. How you code these regions depends on where in the code you are using them.
In both cases, Dreamweaver recognizes the code and will replace the code with the value of the parameter in any page based on this template. To get a sense of how they differ, though, the following examples highlight how to use them.
Example 1: In this example, either method of hand coding an optional region (highlighted in red) will work, because the code is not used to replace the value of a tag's attribute. In both cases, Dreamweaver will see this code in any page based on this template, and will replace the code with the actual defined value (the value will be editable for template users by modifying template properties):
- Works:<title>@@("title")@@</title>
- Works:<title><!-- TemplateExpr expr="title" --></title>
Example 2: In this example, the method of hand coding that uses a Template Expression tag is incorrect, because the code IS used to replace the value of tag's attribute. For the first method, though, Dreamweaver will see this code in any page based on this template, and will replace the code with the actual defined value (the value will be editable for template users by modifying template properties). For both methods, the code that attempts to describe the parameter is highlighted in red:
- Works:<table border=@@("border")@@ cellpadding=3 cellspacing=0>
- Does not work:<table border=<!-- TemplateExpr expr="border" --> cellpadding=3 cellspacing=0>