Re: Is there a more elegant way to do null checks?

"Newman, John W" <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <D688C4D318A63D4290AA94A33E06F7D20285E7EDDB@msxmbxnsprd14.acct.upmchs.net>
The ! operator is the best

${(patient.name.first)!"<Not Entered>"}

[#list (patient.diagnoses)![] as dx]
  ${(dx.code)!"<Unknown>"}
[/#list]

[#if (template.scripts.inline.head)!{}?has_content]    
  Do something
[/#if]

For the last one there I am not 100% on the order of precedence, you may need an extra paren before the ?


-----Original Message-----
From: Jan Haderka [mailto:[email protected]] 
Sent: Wednesday, March 24, 2010 4:52 PM
To: FreeMarker-user
Subject: Re: [FreeMarker-user] Is there a more elegant way to do null checks?


When I rewrote my tag files as macros, I produced a lot of bloated template
code like so:

[#if (template?? && template.scripts?? && template.scripts.inline?? &&
template.scripts.inline.head??)]do something[/#if]

Is there a more elegant way to check if the head value is empty? I have

I'm not an expert, but would not something like:

[#if (template.scripts.inline.head)??]do something[/#if]

do?

Jan

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user


------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.