A lot of people get DE() wrong.

IIF does not short-circuit 
(http://en.wikipedia.org/wiki/Short-circuit_evaluation), meaning that 
your DE() gets evaluated even if the condition is FALSE.  So, this will 
break:
    #iif(false, notFalse, false)#
since notFalse does not exist.  Same here:
    #iif(true, true, fols)#
since fols does not exist.  And finally your code:
    #iif(false, DE(x.classAssign["#y#head"]), DE(''))#
breaks since x.classAssign["NAMEhead"] does not exist.

DE evaluates a STRING parameter and finds double-quotes.  If you pass in 
a variable, it looks for the value of that variable.  Since you are 
passing x.classAssign["#y#head"], it looks for x.classAssign["NAMEhead"] 
and breaks.

This will work: evaluate(DE("x.classAssign['#y#head']"))  - notice the 
single-quotes surrounding #y#head!  This is because we don't want DE to 
escape this, so we don't want to wrap it around double-quotes!

Here is the code (I used "no value" instead of "", but it's still the 
same code that you use):

<cfset x.classAssign = {
    NameHead = "this head",
    NoNameHead = "that head"
} />
<cfoutput>
    <cfset y = "Name" />
    #iif(StructKeyExists(x.classAssign,"#y#head"), 
evaluate(DE("x.classAssign['#y#head']")), DE("no value"))#<hr />
    <cfset y = "NoExist" />
    #iif(StructKeyExists(x.classAssign,"#y#head"), 
evaluate(DE("x.classAssign['#y#head']")), DE("no value"))#<hr />

    <cfset Y = 'Any' />
    See how these two differ: <br />
    #DE("x.classAssign['#y#head']")#<br />
    #DE('x.classAssign["#y#head"]')#
</cfoutput>

Michael Grant wrote:
> HA! So I'm not the only one!
> So I thought DE meant "Delay Evaluation" as in "Don't evaluate what's in
> these little brackets this until you've satisfied the IIF condition."
>   
>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Order the Adobe Coldfusion Anthology now!
http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:336885
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/groups/cf-talk/unsubscribe.cfm

Reply via email to