Dealing with empty node

steelej's Avatar


04 Apr, 2014 04:35 PM

In the attached page, I want to display items for Related Documents at the end only when values are entered. I tried #if ($docs.size() > "0") but can't get it to work. If it were working, I don't think it would be the right choice for the way I have this set up as the $docs.size() comes up as 1 when there is no entry.

  1. 1 Posted by steelej on 04 Apr, 2014 06:02 PM

    steelej's Avatar

    This is not urgent. I would be curious as to the proper way to do this. I thought on it a while and achieved what I wanted by checking the first item under docs for text (which all items would have to have). I used that for my conditional: #if ($dochk.trim() != "")

    It works.

  2. 2 Posted by Ryan Griffith on 04 Apr, 2014 06:49 PM

    Ryan Griffith's Avatar

    Hi Jim,

    Have you tried using #if ($docs.size() > 0) by chance? Note that the size() method returns an integer and not a string.

    I noticed that the doc items are composed of two asset choosers. You could try using the XPath Tool to filter out items that have a value or a chosen asset and then check for the size of the filtered items. For example:

    #set ($docs = $_XPathTool.selectNodes($dd, "docs/item[localfile/path != '/' or localpage/path != '/']"))
    #if ($docs.size() > 0)
        ... Code here ...

    Please let me know if you have any questions.


  3. 3 Posted by Ryan Griffith on 08 Apr, 2014 05:53 PM

    Ryan Griffith's Avatar

    Hi Jim,

    Just wanted to follow up to see if you had a chance to view my recent comment. Were you able to get your Velocity code working?

    Please let us know if you have any questions.


  4. steelej closed this discussion on 09 Apr, 2014 01:12 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac