Chapter 7: Reusing Code
79
When CFASSOCIATE is encountered in a sub tag, the sub tag’s attributes are
automatically saved in the base tag. The attributes are in a structure appended to the
end of an array whose name is ‘ThisTag.collection_name'. The default value for the
DataCollection attribute is ‘AssocAttribs'. This attribute should be used only in cases
where the base tag can have more than one type of sub tag. It is convenient for keeping
separate collections of attributes, one per tag type.
CFASSOCIATE performs the following operations:
<!--- Get base tag instance data --->
<CFSET data = getBaseTagData(baseTag).thisTag>
<!--- Create a string with the attribute collection name --->
<CFSET collectionName = ’data.#dataCollection#"’>
<!--- Create the attribute collection, if necessary --->
<CFIF not isDefined(collectionName)>
<CFSET "#collectionName#" = arrayNew(1)>
</CFIF>
<!--- Append the current attributes to the array --->
<CFSET temp=arrayAppend(evaluate(collectionName), attributes)>
The CFML code accessing sub-tag attributes in the base tag could look like the
following:
<!--- Protect against no sub-tags --->
<CFPARAM Name=’thisTag.assocAttribs’ default=#arrayNew(1)#>
<!--- Loop over the attribute sets of all sub tags --->
<CFLOOP index=i from=1
to=#arrayLen(thisTag.assocAttribs)#>
<!--- Get the attributes structure --->
<CFSET subAttribs = thisTag.assocAttribs[i]>
<!--- Perform other operations --->
</CFLOOP>
Ancestor data access
The ancestor's data is represented by a structure object that contains all the ancestor's
data.
The following set of functions provide access to ancestral data:
•
GetBaseTagList()
— Returns a comma-delimited list of uppercased ancestor
tag names. An empty string is returned if this is a top-level tag. The first element
of a non-empty list is the parent tag.
•
GetBaseTagData(TagName, InstanceNumber=1)
— Returns an object that
contains all the variables, scopes, etc. of the nth ancestor with a given name. By
default, the closest ancestor is returned. If there is no ancestor by the given
name or if the ancestor does not expose any data (such as CFIF), an exception is
thrown.
Summary of Contents for COLDFUSION 4.5-DEVELOPING WEB
Page 1: ...Allaire Corporation Developing Web Applications with ColdFusion ColdFusion 4 5...
Page 14: ...xiv Developing Web Applications with ColdFusion...
Page 26: ...xxvi Developing Web Applications with ColdFusion...
Page 34: ...8 Developing Web Applications with ColdFusion...
Page 70: ...44 Developing Web Applications with ColdFusion...
Page 84: ...58 Developing Web Applications with ColdFusion...
Page 114: ...88 Developing Web Applications with ColdFusion...
Page 148: ...122 Developing Web Applications with ColdFusion...
Page 174: ...148 Developing Web Applications with ColdFusion...
Page 208: ...182 Developing Web Applications with ColdFusion...
Page 244: ...218 Developing Web Applications with ColdFusion...
Page 274: ...248 Developing Web Applications with ColdFusion...
Page 288: ...262 Developing Web Applications with ColdFusion...
Page 300: ...274 Developing Web Applications with ColdFusion...
Page 350: ...324 Developing Web Applications with ColdFusion...
Page 362: ...336 Developing Web Applications with ColdFusion...