Custom tag attribute values are passed from the calling page to the custom tag page as name-value pairs. CFML custom tags support required and optional attributes. Custom tag attributes conform to the following CFML coding standards:
attribute_name
syntax when referring to passed attributes to distinguish them from custom tag page local variables.
<!--- The value of the variable Attributes.Name comes from the calling page. If the calling page does not set it, make it "Who". ---> <cfparam name="Attributes.Name" default="Who">
The following example creates a custom tag that uses an attribute that is passed to it to set the value of a variable called Doctor on the calling page.
The calling page uses the getmd custom tag and displays the results.
The following table describes the code and its function:
Code |
Description |
---|---|
<cfset NameYouEntered="Smith"> |
In the calling page, create a variable NameYouEntered and assign it the value Smith. |
<cfoutput> Before you leave this page, you're #Variables.NameYouEntered#.<br> </cfoutput> |
In the calling page, display the value of the NameYouEntered variable before calling the custom tag. |
<cf_getmd Name="#NameYouEntered#"> |
In the calling page, call the getmd custom tag and pass it the Name attribute whose value is the value of the local variable NameYouEntered. |
<cfparam name="Attributes.Name" default="Who"> |
The custom tag page normally gets the Name variable in the Attributes scope from the calling page. Assign it the value Who if the calling page did not pass an attribute. |
<cfset Caller.Doctor="Doctor " & Attributes.Name> |
In the custom tag page, create a variable called Doctor in the Caller scope so it exists in the calling page as a local variable. Set its value to the concatenation of the string "Doctor" and the value of the Attributes.Name variable. |
<cfoutput> You are now #Variables.Doctor#.<br> </cfoutput> |
In the calling page, display the value of the Doctor variable returned by the custom tag page. (This example uses the Variables scope prefix to emphasize the fact that the variable is returned as a local variable.) |