Sort Tool: last-published-on

espanae's Avatar

espanae

Jun 24, 2011 @ 09:53 PM

I wrote a Velocity script to view our most recently published pages (using an index block). The report starts off as anticipated, in chronological order, but after a while the dates start going out of order. The script is attached. Did I do something wrong?

  1. 1 Posted by Charlie Holder on Jun 25, 2011 @ 04:04 AM

    Charlie Holder's Avatar

    Can you attach a sample of XML data that this format is processing as well as the HTML outcome you're getting as output?

  2. 2 Posted by espanae on Jun 28, 2011 @ 05:30 PM

    espanae's Avatar

    Sure.
    You'll notice the System Pages are correctly in chronological order (correctly) but then start repeating: http://union.edu/_dev8080/reports/recently-published/standard-content/

    It's running against an index block (content type) which I've attached. I also attached an updated version of the Velocity script with comments.

    Thanks for your help.

  3. 3 Posted by Charlie Holder on Jul 03, 2011 @ 06:26 PM

    Charlie Holder's Avatar

    Oh man. This one was tricky to diagnose.

    I don't really know why nor do I understand the implications inside Cascade, but not all of the system-page nodes contained in your sample XML have a last-published-on node. I think that because the Velocity Format can't find the node to sort on with the $_SortTool call some weird stuff is happening. I'm sorry I personally cannot offer some more concrete advice. I will bump this thread to support for an internal discussion and then maybe they can offer something more detailed.

    With all that said, I was able to achieve a properly sorted page by adding a filter to the initial $_XPathTool call. The filter only includes pages that have a last-published-on node.

    I also made one (small) additional change to the Format. Instead of having the #if statement inside your #foreach loop, you can filter out the pages that belong to the "development" Site in the initial $_XPathTool call similar to the previous paragraph.

    Here's a copy of the Format I ended with. Please let me know if you have any questions.

    ## // Get all System-Pages sorted by date published.
    
    #set ( $sys_pages = $_XPathTool.selectNodes($contentRoot, "/system-index-block/system-page[last-published-on][is-published='true'][site!='development']") )
    $_SortTool.addSortCriterion("last-published-on", "", "number", "descending", "")
    $_SortTool.sort($sys_pages)
    
    
    ## // Style the table with CSS
    
    <style>
    thead th    { text-align: center; font-weight: bold; }
    td th       { margin-left: 10px; margin-right: 10px; }
    </style>
    
    
    ## // Table headers
    
    <table style="width:900px;">
    <thead>
        <tr>
            <th>Last Published Date</th>
            <th>Last Published By</th>
            <th>Link</th>
        </tr>
    </thead>
    
    
    ## // For each System Page, create a table row
    
    #foreach ( $page in $sys_pages )
    
        #set ( $by = $page.getChild("last-published-by").value )
        #set ( $on = $page.getChild("last-published-on").value )
    
        <tr>
            <td>$_DateTool.format("MM/dd/yy hh:mm:ss a", $_DateTool.getDate($on))</td>
            <td>
                #if ( $by != "" ) ${by} #else N/A #end
            </td>
            <td>
                <a href="${page.getChild("link").value}">
                    ${page.getChild("path").value}
                </a>
            </td>
        </tr>
    
    #end
    
    
    ## // Close the table tag
    
    </table>
    
  4. 4 Posted by espanae on Jul 05, 2011 @ 03:06 PM

    espanae's Avatar

    Charlie, thank you for resolving the issue.
    I'll keep you posted if I notice any other "weirdness" with our data.

  5. Charlie Holder closed this discussion on Jul 26, 2011 @ 06:00 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