map

map

Loops over a set of values and gathers return values from enclosed code. These new values are collected into an output set.

Metadata

Examples

The basic use case is converting between complex data types. The following snippet creates a query from the url struct:
<misc:map values="#url#" resulttype="querynew('key,value')">
    <cfset sendback[1].key = index />
    <cfset sendback[1].value = value />
</misc:map>
<cfdump var="#result#" />
This is a more complex example from core .This snippet loops through the application.stCOAPI struct, then through the qWebskins query. As it goes through it is constructing a struct of webskin paths:
<misc:map values="#application.stCOAPI#" index="thistype" value="metadata" result="stWebskins" resulttype="struct" sendback="typesendback">
    <misc:map values="#metadata.qWebskins#" index="currentrow" value="webskin" result="typesendback.#thistype#" resulttype="struct" sendback="webskinsendback">
        <cfif len(webskin.methodname) and webskin.methodname neq "deniedaccess">
            <cfset webskinsendback[webskin.methodname] = webskin.path />
        </cfif>
    </misc:map>
</misc:map>
<cfdump var="#stWebskins#" />

Attributes

Name Type Required Default Options Description
values1 string No #attributes.values# valuesN can be used to input any number of input sets for processing
values1 string No The set of source values. Can be a struct, array, list, or query.
index string No index The variable that will contain the index of the source item. For structs this is the key.
value string No value The variable that will contain the value of the source item. For queries this is a struct of the column values. If this value is a non-simple value (e.g. struct) editing it will alter the source set. Defaults to "value"
sendback string No sendback The variable that enclosed code will add output items to. The type of this variable depends on the output set type: For structs this is a struct which gets merged into the output set. For arrays this is an array that gets appended to the output set. For lists this is a string that gets appended to the output list. For queries this is an array of row structs (containing one empty struct by default), each of which is appended to the output query. If this variable is "empty" (e.g. empty struct) no items are added to the output set. Defaults to "sendback"
resulttype string No Same as values struct, array, list, querynew('col1,col2') The output set type. Defaults to the same type as the source set.
result string No result The variable the output set is stored in once this tag has finished execution. Defaults to "result"
delimiters list No , Only applies for resulttype="list". Specifies an alternate delimiter.
delimitersin string No #attributes.delimiters# Only applies when values is a list. Specifies an alternate delimiter for the input list only.
delimitersout list No #attributes.delimiters# Only applies for resulttype="list". Specifies an alternate delimiter for the output list only.