Empty node

steelej's Avatar

steelej

Apr 29, 2013 @ 03:49 PM

For an emergency alert page, I'm trying to produce a default date and text when no update to the alert has been entered. I'm grabbing the current date successfully but, for reasons unknown to me, my if/else statement is not working. The if-statement in the script works--if the date node has a value. If no value for date is present, the else statement is not working.

I'd appreciate any help.

Jim

  1. 1 Posted by Ryan Griffith on Apr 29, 2013 @ 07:02 PM

    Ryan Griffith's Avatar

    Hi Jim,

    There are a few items I noticed with your Format that may be causing problems:

    • The check to see if there are $updates is inside of your #foreach, so this means there will always be at least one and the else portion of the conditional will never fire.
    • You are creating a current date variable every time the #foreach iterates; it would be much more efficient to create this variable once before looping and simply re-use it.

    Try the following Format as a starting point and let me know how it works out for you:

    #set ($updates = $_XPathTool.selectNodes($contentRoot, "/system-index-block/calling-page/system-page/system-data-structure/updates/item[date!=''] "))
    
    <h2>Updates</h2>
                
    #if ( $updates.size() < 1 )
      #set ($dateTime = $_DateTool.getDate())
      <h3>${_DateTool.format("MMMM dd, yyyy", $dateTime)}</h3>
      <p>There are no updates at this time.</p>
    #else      
      #foreach ($update in $updates)
        #set ($date = $update.getChild("date").value)
        #set ( $datec = $_DateTool.toDate("MM-d-yyyy","$date") )
        #set ( $newDateText = $_DateTool.format("MMMM dd, yyyy", $datec) )
        #set ($content = $update.getChild("content"))
    
        <h3>${newDateText}</h3>
      
        <p>$_SerializerTool.serialize($content, true)</p>
    
        <hr />
              
      #end
    #end
    

    Please let me know if you have any questions.

    Thanks

  2. 2 Posted by steelej on Apr 29, 2013 @ 08:00 PM

    steelej's Avatar

    Thanks Ryan. That makes sense and works.

    Jim

  3. 3 Posted by Ryan Griffith on Apr 29, 2013 @ 09:02 PM

    Ryan Griffith's Avatar

    Not a problem at all, Jim, thank you for following up. I am glad to hear that did the trick.

    Have a great day!

  4. Ryan Griffith closed this discussion on Apr 29, 2013 @ 09:02 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? 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