Trouble pulling start-date

steelej's Avatar


17 Oct, 2012 07:34 PM

I have a feeling I'm missing something simple again here, but I've been at it a while with no result. For some reason, my script won't pull the start-date as I've written it (currently commented out in the foreach statement). Can you tell me where I've gone awry?

  1. 1 Posted by Ryan Griffith on 17 Oct, 2012 08:18 PM

    Ryan Griffith's Avatar


    It sounds as though the DateTool is unable to initialize using the value of the start-date element. Let's try the following, which will use the java.util.Date.parse() method to create a new Date object from the given string. From there we can use the DateTool to format the new date object:

    #set ($articles = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page/system-data-structure/news/article"))
    #set ($count = 0)
    #if ($articles.size() > $count)
        <div class="category" id="news-box">
        <div class="subheading" id="news">
          <h3>What's Happening Now</h3>
      #foreach ($article in $articles)
            #set ($title = $article.getChild("title"))
            #set ($path = $article.getChild("path").value)
            #set ($image = $article.getChild("content").getChild("system-data-structure").getChild("image").getChild("lead").getChild("path").value)
            #set ($caption = $article.getChild("content").getChild("system-data-structure").getChild("image").getChild("caption").value)
            #set ($abstract = $article.getChild("summary"))
            #set ($date = $article.getChild("start-date").value)
            #set ($dateObj = $_DateTool.getDate())
            #set ($date = $dateObj.parse($date))
            #set ($count = $count + 1)
       #if ($count == 1)
                    <div id="top-story">
                        #if ($image != "/")
                            <a href="${path}">
                                <img src="${image}" alt=" " />
                        #if ($caption != "")
                    #if ($abstract != "")
                        <p>$_SerializerTool.serialize($abstract, true) <a href="${path}" class="more">// read more</a></p>
                        <p><a href="${path}" class="more">// read more</a></p>
                <div id="latest-news">
                            #if ($date != "")
                                <h4>$_DateTool.format('MMMM dd, yyyy', $date)</h4>
                            <a href="${path}">
                                $_SerializerTool.serialize($title, true)
    <strong id="visit-archives">News Archive: <a href="">2012</a> | <a href="">2011</a> | <a href="">2010</a></strong><br />
     <strong id="visit-archives">Features Archive: <a href="">2012</a> | <a href="">2011</a> | <a href="">2010</a></strong>

    Please let me know if this works out or if you have any questions.


  2. 2 Posted by steelej on 17 Oct, 2012 08:26 PM

    steelej's Avatar

    That did the trick. thanks

  3. steelej closed this discussion on 17 Oct, 2012 08:26 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