| | 1 | [[PageOutline]] |
| | 2 | |
| | 3 | = View API = |
| | 4 | |
| | 5 | Inside of a .CFM template used as a view, two CFC instances are available in the unnamed or "variables" scope: viewstate and viewcollection. |
| | 6 | |
| | 7 | Viewstate is used to access values from the viewstate. |
| | 8 | |
| | 9 | Viewcollection is used to access the rendered HTML of prior views. |
| | 10 | |
| | 11 | == !ViewCollection == |
| | 12 | |
| | 13 | 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. |
| | 14 | |
| | 15 | 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): |
| | 16 | |
| | 17 | {{{ |
| | 18 | <!-- In ModelGlue.xml --> |
| | 19 | |
| | 20 | <event-handler name="viewstacking"> |
| | 21 | |
| | 22 | <views> |
| | 23 | |
| | 24 | <include name="body" template="dspBody.cfm" /> |
| | 25 | |
| | 26 | <include name="main" template="dspTemplate.cfm" /> |
| | 27 | |
| | 28 | </views> |
| | 29 | |
| | 30 | </event-handler> |
| | 31 | |
| | 32 | <!--- dspBody.cfm ---> |
| | 33 | |
| | 34 | <p>Hi, I'm dspBody.cfm!</p> |
| | 35 | |
| | 36 | <!--- dspTemplate.cfm ---> |
| | 37 | |
| | 38 | <h1>dspTemplate.cfm</h1> |
| | 39 | |
| | 40 | <cfoutput>#viewcollection.getView("body")#</cfoutput> |
| | 41 | }}} |
| | 42 | |
| | 43 | == !ViewCollection.Exists(name:string) == |
| | 44 | |
| | 45 | ==== Description: ==== |
| | 46 | |
| | 47 | Does a view of the given name exist in the viewcollection? |
| | 48 | |
| | 49 | ==== Returns: ==== |
| | 50 | |
| | 51 | Boolean |
| | 52 | |
| | 53 | ==== Arguments: ==== |
| | 54 | |
| | 55 | Name (required) - The name of the view to check |
| | 56 | |
| | 57 | == !ViewCollection.!GetView(name:string) == |
| | 58 | |
| | 59 | ==== Description: ==== |
| | 60 | |
| | 61 | 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.'' |
| | 62 | |
| | 63 | ==== Returns: ==== |
| | 64 | |
| | 65 | String |
| | 66 | |
| | 67 | ==== Arguments: ==== |
| | 68 | |
| | 69 | Name (required) - The name of the view's content to retrieve |
| | 70 | |
| | 71 | == Viewstate == |
| | 72 | |
| | 73 | 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. |
| | 74 | |
| | 75 | == Viewstate.Exists(name:string) == |
| | 76 | |
| | 77 | ==== Description: ==== |
| | 78 | |
| | 79 | Does a value of the given name exist in the viewstate? |
| | 80 | |
| | 81 | ==== Returns: ==== |
| | 82 | |
| | 83 | Boolean |
| | 84 | |
| | 85 | ==== Arguments: ==== |
| | 86 | |
| | 87 | Name (required) - The name of the value to check |
| | 88 | |
| | 89 | == Viewstate.!GetAll() == |
| | 90 | |
| | 91 | ==== Description: ==== |
| | 92 | |
| | 93 | Returns the structure that contains all viewstate members ''by reference''. |
| | 94 | |
| | 95 | ==== Returns: ==== |
| | 96 | |
| | 97 | Struct |
| | 98 | |
| | 99 | ==== Arguments: ==== |
| | 100 | |
| | 101 | None |
| | 102 | |
| | 103 | == Viewstate.!GetValue(name:string [, default:any]) == |
| | 104 | |
| | 105 | ==== Description: ==== |
| | 106 | |
| | 107 | Returns a value from the viewstate, such as a form or url variable. |
| | 108 | |
| | 109 | ==== Returns: ==== |
| | 110 | |
| | 111 | Any |
| | 112 | |
| | 113 | ==== Arguments: ==== |
| | 114 | |
| | 115 | Name (required) - The name of the value to retrieve |
| | 116 | |
| | 117 | Default (optional) - If the value does not exist, a default value to set into the viewstate and then return |