Trouble pulling start-date

steelej's Avatar

steelej

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

    Hi,

    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>
          </div>
          
      #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=" " />
                            </a>
                        #end    
                        #if ($caption != "")
                         <h1>$caption</h1>
                            
                        #end    
                    
                    #if ($abstract != "")
                        <p>$_SerializerTool.serialize($abstract, true) <a href="${path}" class="more">// read more</a></p>
                    #else
                        <p><a href="${path}" class="more">// read more</a></p>
                    #end
                #else
                <div id="latest-news">
                    <ul>
                        <li>
                            #if ($date != "")
                                <h4>$_DateTool.format('MMMM dd, yyyy', $date)</h4>
                            #end
                            <a href="${path}">
                                $_SerializerTool.serialize($title, true)
                            </a>
                        </li>
                    </ul>
                #end
                </div>
        #end
      
    
     
    #end    
    <strong id="visit-archives">News Archive: <a href="http://www.wit.edu/news/2012/index.html">2012</a> | <a href="http://www.wit.edu/news/2011/index.html">2011</a> | <a href="http://www.wit.edu/news/2010/index.html">2010</a></strong><br />
     <strong id="visit-archives">Features Archive: <a href="http://www.wit.edu/features/2012/index.html">2012</a> | <a href="http://www.wit.edu/features/2011/index.html">2011</a> | <a href="http://www.wit.edu/features/2010/index.html">2010</a></strong>
       </div>
    

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

    Thanks

  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

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