| Version 2 (modified by cfgrok, 17 years ago) |
|---|
View API
Inside of a .CFM template used as a view, two CFC instances are available in the unnamed or "variables" scope: viewstate and viewcollection.
Viewstate is used to access values from the viewstate.
Viewcollection is used to access the rendered HTML of prior views.
ViewCollection
In a .CFM template used as a View in a Model-Glue Application, the "viewcollection" variable gives access to the rendered results of prior views.
This can be used to "stack" views. The following example shows a simple event handler in which one view, dspBody.cfm, is used inside of another (dspTemplate.cfm):
<!-- In ModelGlue.xml -->
<event-handler name="viewstacking">
<views>
<include name="body" template="dspBody.cfm" />
<include name="main" template="dspTemplate.cfm" />
</views>
</event-handler>
<!--- dspBody.cfm --->
<p>Hi, I'm dspBody.cfm!</p>
<!--- dspTemplate.cfm --->
<h1>dspTemplate.cfm</h1>
<cfoutput>#viewcollection.getView("body")#</cfoutput>
ViewCollection.Exists(name:string)
Description:
Does a view of the given name exist in the viewcollection?
Returns:
Boolean
Arguments:
Name (required) - The name of the view to check
ViewCollection.GetView(name:string)
Description:
Returns the rendered results of a prior rendered view whose NAME attribute is the name argument passed. If the view does not exist, returns an empty string.
Returns:
String
Arguments:
Name (required) - The name of the view's content to retrieve
Viewstate
In a .CFM template used as a View in a Model-Glue Application, the "viewstate" variable gives access to form and url data, along with any values added in a controller function through the Event.SetValue() method of the Event API.
Viewstate.Exists(name:string)
Description:
Does a value of the given name exist in the viewstate?
Returns:
Boolean
Arguments:
Name (required) - The name of the value to check
Viewstate.GetAll()
Description:
Returns the structure that contains all viewstate members by reference.
Returns:
Struct
Arguments:
None
Viewstate.GetValue(name:string [, default:any])
Description:
Returns a value from the viewstate, such as a form or url variable.
Returns:
Any
Arguments:
Name (required) - The name of the value to retrieve
Default (optional) - If the value does not exist, a default value to set into the viewstate and then return
![(please configure the [header_logo] section in trac.ini)](/ModelGlue.com/trac.cgi/chrome/site/your_project_logo.png)