Was this page helpful?

PageSort

     

    Description:

     

    Sort sub-pages of current page by SORT page variable then by alpha.

     

    Installation:

     

    1. Create a template, call it "Template:PageSort".  You must have "unsafecontent" permission for this to work.
    2. Create a "Dekiscript" block on the template page (use the "Style" menu in the editor")
    3. Copy the code from the template code section below and paste it into the Dekiscript block.  To copy, move your mouse over the top right corner of the source code, and click the "view source" button.  This will pop up a window with the source code.  Select all, then copy to clipboard.
    4. Make sure there isn't an extra blank paragraph after the Dekiscript block! Do this every time you edit!!!  
    5. Save.

     

     

    Parameters:

     

    Name Type Default Description
     sortPath  incoming  nil

    Page path to display subPages from - default is current page.

    This is an optional parameter.

     

    Usage:

     

    PageSort(sortPath:any):html

     

    This will sort the sub-pages of the page found at the path specified by the optional parameter sortPath in alphabetical order.  If sortPath has not been specified, then the sub-pages of the current page will be sorted in alphabetical order.

     

    If there is a requirement to sort the sub-pages differently, for example if you have sub-pages like "Introduction", "Getting Started" and "Advanced Concepts", and you want them to appear in that order, you would need to set the page properties on each page to the named property "SORT" with ascending numerical values on each page, e.g. "10", "20", "30".  I would recommend using multiples of 10 as you never know when you might want to add another page within the existing sort order.  To see how to set page properties see Set_Page_Properties.

    Output:

     

    Bulleted list of sub-pages (one level deep) as links, sorted by SORT property (numerical) against each page and then by alpha.

     

    Template code

     

    // aleggett with assistance from SteveB, neilw & rberinger 10.05.2010
    
    // get the initial list of pages
    
    var sortPath = $0 ?? $sortPath ?? _;
    var subPageList = [];
    if (sortPath == _){
       let subPageList = map.values(page.subpages);
    } else {
       let subPageList = map.values(wiki.getPage(sortPath).subpages);
    };
    
    // sort by SORT property and/or by alpha
    
    var plist = list.sort{list:subPageList, compare:"(
       var L = num.cast($left.properties['SORT'].text);
       var R = num.cast($right.properties['SORT'].text);
       (L && R) ? (L - R) : string.compare($left.title, $right.title, true)
    )"};
    
    // show the pages
    foreach (var p in plist){
       <ul><li>web.link(p.uri,p.title);</li></ul>;
    };
    Was this page helpful?
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by