nodes - How to define if object is equal to null in magnolia freemarker(.ftl) -
i working on piece of component, need if else statement done filter out wether page object null or not, here attempts:
[#assign page = cmsfn.page(component)] [#if page null ] // not working... [@cms.component content=cmsfn.ascontentmap(component) editable=false/] [/#if]
and one
[#assign page = cmsfn.page(component)] [#if !page?has_content ] // not working... [@cms.component content=cmsfn.ascontentmap(component) editable=false/] [/#if]
what trying here is, if page object null , component rending, these page object jrc children nodes, when rendering component type of node mess thing template, need filter out , make sure page null, render.
any suggestions? please provide me code example. thanks
the template language of freemarker (2.x) has this... quirk, doesn't have null
value. thus, can't store null
in variable. when have foo.bar
bar
corresponds java getbar()
return null
, far template language concerned, foo
doesn't contain bar
. and, referring doesn't exist illegal, unless, apply null
/missing handler operator directly on referring expression (like foo.bar!'mydefault'
or foo.bar??
).
so simplest approach avoid assignment [#if cmsfn.page(component)??]...[/#if]
. that's not acceptable have page
second time further down. can use default can differentiate non-default. assuming page
object ?has_content
gives true
(and unless using strange objectwrapper
does), default value {}
(empty hash) suffices. exp!
operator can used shorthand, gives default value ?has_content
false:
[#assign page = cmsfn.page(component)!] [#if page?has_content] [@cms.component content=cmsfn.ascontentmap(component) editable=false/] ... `page`, otherwise need not use #assign. [#else] ... don't `page`, it's strange default object. [/#if]
Comments
Post a Comment