Will,

${cart.billingAddressCompany!} should do the trick. This is one the of most annoying thing when you start using FreeMarker, coming from JSP. Hopefully, you'll soon realize it's a GOOD THING. You and your template should know if your model (cart in this case) is complete or not. JSP's silent ignoring of non-existing values is imo an open-door for bugs and unexpected behaviour. (think how they both will behave the day you rename your "billingAddressCompany" property, for instance)

You should also be aware that FreeMarker differentiates (or will, in a future version, I don't exactly remember the current status) between a null value and a non-existing value (${bean.foo} would behave differently if bean has a getFoo() method returning null, or no such method)

http://documentation.magnolia-cms.com/reference/freemarker.html#References
http://freemarker.sourceforge.net/docs/dgui_quickstart_template.html#autoid_12

Cheers,

-g

ps: for more advanced discussion, you might find the freemarker user- list (and its archive) a good resource too.

On May 6, 2009, at 3:08 PM, Will Scheidegger wrote:


Dear Magnolians

Since everybody @ Magnolia seems to be that much fond of Freemarker we're trying not to swim too much against the current. I'm having one very annoying problem though - I often get error messages like this:

Expression cart.billingAddressCompany is undefined on line 19, column 11 in ch/fastforward/sfgb/mailtemplates/ shopConfirmationMail_de.txt.
The problematic instruction:
----------
==> ${cart.billingAddressCompany} [on line 19, column 9 in ch/ fastforward/sfgb/mailtemplates/shopConfirmationMail_de.txt]
----------

Java backtrace for programmers:
----------
freemarker.core.InvalidReferenceException: Expression cart.billingAddressCompany is undefined on line 19, column 11 in ch/ fastforward/sfgb/mailtemplates/shopConfirmationMail_de.txt. at freemarker.core.TemplateObject.assertNonNull(TemplateObject.java: 124)
        ...

Now if I place every ${myVar} in a <#if cart.orderAddressMobile?? >...</#if> things would be fine, but isn't there a simple way to do this? Is there a setting or something that simply does not print out anything if the var is not defined? I'm sure I _must_ be missing something, because this works like a charm in JSP...

Thanks for the insight.

-will

----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------


----------------------------------------------------------------
For list details see
http://www.magnolia-cms.com/home/community/mailing-lists.html
To unsubscribe, E-mail to: <[email protected]>
----------------------------------------------------------------

Reply via email to