cancel
Showing results for 
Search instead for 
Did you mean: 

Global Search

jlmarques
Champ in-the-making
Champ in-the-making
Hey there, I setup two web forms so that I can produce two types of content: pages and articles, they have distinct formats, but share some common properties, like title, author and body.

I am able to retrieve the results using this ftl:

<#list resultset as node>
    <ul>
   <#if node.isDocument>
      <li>${node.name} - ${xmldate(node.properties.modified)}</li>
    </#if>
    </ul>
</#list>

But obviosly I have no interest in getting the document properties, I want access the data inside the xml:


<#list resultset as node>
    <#if node.isDocument>
      <#assign dom=node.xmlNodeModel>
      <#if dom.page.title??>
            <h2>${dom.page.title}<h2>
            <p>${dom.page.body}<p>
      </#if>
      <#if dom.article??>
            <h2>${dom.article.title}<h2>
            <p>${dom.article.body}<p>
      </#if>      
    </#if>
</#list>

I get this error:
freemarker.core.NonStringException - Error on line 5, column 39 in cms/search/search.get.html.ftl Expecting a string, date or number here, Expression dom.page.title is instead a freemarker.ext.dom.NodeListModel

What can I do to bypass this?

I've tried using ${(dom.page.title)!} but still get the same error, obviously dom.page.title exists but it's not a string, date or number type.
I'm kind of stuck here.
:roll:
2 REPLIES 2

mikeh
Star Contributor
Star Contributor
You haven't posted the XML you're trying to parse, but I suspect you're falling foul of the problem discussed in the book/chapter/title example on this Freemarker documentation page:
http://freemarker.org/docs/xgui_imperative_learn.html

Thanks
Mike

jlmarques
Champ in-the-making
Champ in-the-making
Thanks for the tip!

This line:
<#if dom.page.title??> 
Was not really working since it always returns true, but this works:

<#if dom.page?size == 1>