coldfusion Variables Using cfparam


Example

The <cfparam> tag creates a variable if it does not already exist. You can assign a default value using the default attribute. This can be used if you want to create a variable, but don't want to overwrite it if it has been previously created elsewhere.

Here the variable hasn't been set previously, so it will be assigned with the <cfparam> tag.

<cfparam name="firstName" default="Justin">
<cfoutput>
    Hello #firstName#
</cfoutput>

Here the variable has already been assigned using the <cfset> tag, so this value will override the default value in the <cfparam> tag.

<cfset firstname="Justin">

<cfparam name="firstName" default="Barney">
<cfoutput>
    Hello #firstName#
</cfoutput>