How to use variable prefixes in ColdFusion

ColdFusion variable prefixes

VariablePrefixes.cfm


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>coldfusion variable prefixes - how to use in coldfusion application</title>
</head>

<body>
<h2 style="color:DarkBlue; font-style:italic">coldfusion variable prefixes example: how to use</h2>
<hr width="500" align="left" color="LightBlue" />
<br />
<!--enable session management in application.cfm file-->

<cfset Variables.MyNumber=2>
<cfset Session.MyNumber=5>
<cfset Application.MyNumber=10>
<cfset Total=MyNumber+MyNumber+MyNumber>
<cfset TotalWithPrefixes=Variables.MyNumber+Session.MyNumber+Application.MyNumber>


<table border="0" cellpadding="2" cellspacing="2" bgcolor="OrangeRed">
 <tr style="background-color:Crimson; color:Snow; font-size:large;">
     <td>Variable=Value</td>
     <td>Output</td>
    </tr>
 <cfoutput>
        <tr style="background-color:HotPink; color:Snow;">
            <td>Variables.MyNumber=2</td>
            <td>#Variables.MyNumber#</td>
        </tr>
        <tr style="background-color:HotPink; color:Snow;">
            <td>Session.MyNumber=5</td>
            <td>#Session.MyNumber#</td>
        </tr>
        <tr style="background-color:HotPink; color:Snow;">
            <td>Application.MyNumber=10</td>
            <td>#Application.MyNumber#</td>
        </tr>
        <tr style="background-color:HotPink; color:Snow;">
            <td>Total=MyNumber+MyNumber+MyNumber</td>
            <td>#Total#</td>
        </tr>
        <tr style="background-color:HotPink; color:Snow;">
            <td>TotalWithPrefixes=Variables.MyNumber+Session.MyNumber+Application.MyNumber</td>
            <td>#TotalWithPrefixes#</td>
        </tr>
 </cfoutput>    
</table>

</body>
</html>







More ColdFusion tutorials