I am currently working on piece of component, I need an if else statement to be done to filter out wether a page object is null or not, here is my attempts:
[#assign page = cmsfn.page(component)]
[#if page IS NULL ] // not working...
[@cms.component content=cmsfn.asContentMap(component) editable=false/]
[/#if]
and this one
[#assign page = cmsfn.page(component)]
[#if !page?has_content ] // not working...
[@cms.component content=cmsfn.asContentMap(component) editable=false/]
[/#if]
What I am trying to do here is, if the page object is null , then do the component rending, these page object are jrc children nodes, when rendering component this type of node mess up thing template, so I need to filter out and make sure the page is null, then render.
Any suggestions? please provide me a code example. Thanks
The template language of FreeMarker (2.x) has this... quirk, that it doesn't have a
nullvalue. Thus, you can't storenullin a variable. When you havefoo.barwherebarcorresponds to JavagetBar()which returnnull, then as far as the template language is concerned,foosimply doesn't containbar. And, referring to something that doesn't exist is illegal, unless, you apply anull/missing handler operator directly on the referring expression (likefoo.bar!'myDefault'orfoo.bar??).So the simplest approach is to avoid the assignment like
[#if cmsfn.page(component)??]...[/#if]. But sometimes that's not acceptable as then you have to get thepagefor a second time further down. Then you can use some default that you can differentiate from the non-default. Assuming that for apageobject?has_contentgivestrue(and unless you are using some strangeObjectWrapperit does), a default value like{}(empty hash) suffices. Theexp!operator can be used as a shorthand, as it also gives a default value for which?has_contentis false: