Thursday, December 7, 2017

freemarker boolean weirdness

Freemarker Madness - my coworker helped me learn that
<#if ((allYearsForTrimName!false) && (!canShow("f:listings.seoLinksVariantContext")))>`
does about what you'd expect (in terms of not executing the block if that canShow routine returns true) but
<#if (allYearsForTrimName!false && (!canShow("f:listings.seoLinksVariantContext")))>
(without the safety paren around allYearsForTrimName) always evaluates as true and executes the block.

(I also got reminded myself that while ftl functions can't really print to the page, you can assign stuff to a global-ish variable and print it after ... really, log/printf based debugging will always be a crucical tool in testing your assumptions, even when in a system that has a rich step through debugger.)

So the coworker mentioned freemarket documentation warns about that precedence glitch... but man, that's an annoying one! You really don't want your language messing up boolean operations...


No comments:

Post a Comment