Was this page helpful?

ListPages

     

    Introduction

    The ListPages template makes it a snap to create a bulleted list of linked pages by title, creation date, update date, or view count.  The listing can be reversed and easily limited to the top N items.  If the list is not sorted by title, it will show an extra label with information used to sort the list.

    History

    Version Date Author Description
    1.0 6/09/2009 steveb first version

    Requirements

    • This template requires MindTouch version 9.02

    How do I install it?

    1. Create a template, call it "Template:ListPages" (or rename as you desire).  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 end of this page and paste it into the Dekiscript block.  To copy, click "expand source", then 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.

     

    A quick note about the examples on this page

    For all the examples on this page, the code is shown before the working example.  The code is shown with the syntax extension, and looks like this:

    ListPages()

    This means that the actual code on the page should be enclosed in a DekiScript block.  If you want to copy the code from this page, then use the same procedure as described in steps 2-4 above. 

    How do I use it?

     

    Arguments

    Name
    Type
    Default
    Description
    pages list/map/str subpages of current page List or map of pages to show in the list.  If the parameter is of type str, then it is used as the parent page of the pages to list.
    sort str by title Sort order for list; one of "title", "created", "updated", or "viewcount".
    reverse bool false Reverse order of list.
    limit num show all Limit list to the first N items.
    style str numbered list List style; one of "numbers" or "bullets".
    stripTitlePrefix str none Strip prefix from titles when present (e.g. "How do I...")

    Examples

    List subpages of a page as a bulleted list.

    ListPages{ pages: wiki.getpage("Deki/Extensions").subpages, style: 'bullets' }
    

     

    List the top 10 most popular pages.

    ListPages{ pages: wiki.getpage("Deki/Extensions").subpages, sort: "viewcount", reverse: true, limit: 10 }
    
    1. Produce Slideshow, NewsTicker, Fade Stuff In and Out (20,537 views)
    2. Integrated Bug and Issue Tracker (20,389 views)
    3. ImageMagick Image Effects (18,385 views)
    4. LDAP/ActiveDirectory/eDirectory (17,922 views)
    5. AJAX collapsible wiki tree (17,715 views)
    6. TsTable: Sortable, Paginated, and Zebrified Tables + flexible table generator (15,475 views)
    7. Highcharts - a wrapper for the Highcharts JavaScript graphing package (15,319 views)
    8. Interactive Task List (14,842 views)
    9. Graphviz Flowcharts & Graphs (14,609 views)
    10. Collapsible Table of Contents (14,357 views)

     

    List the three oldest pages.

    ListPages{ pages: wiki.getpage("Deki/Extensions").subpages, sort: "created", limit: 3 }
    
    1. Flickr Slideshows & Badges (created on Jun 12, 2007)
    2. Feed (created on Jun 12, 2007)
    3. Media Player (created on Jun 12, 2007)

    Reference(s)

     

    Credits/Special Thanks

     

    Template/Extension Source Code

    /***
        USAGE:
    
        ListPages(pages, sort, reverse, limit, style, stripTitlePrefix)
            create a bulleted list of sorted pages with an optional limit
    
        PARAMETERS:
    
        (optional) pages : list/map/str
            list/map of pages to list; if pages is a str, then it is used as a path to a parent page to list all subpages; 
            defaults to list of subpages of current page
    
        (optional) sort : str
            sort order for pages; one of 'updated', 'created', 'viewcount', or 'title'; defaults to 'title'
    
        (optional) reverse : bool
            reverse sort order; defaults to false
    
        (optional) limit : num
            maximum number of pages to show; defaults to no limit
    
        (optional) style : str
            list style to use; one of 'numbers' or 'bullets'; defaults to 'numbers'
            
        (optional) stripTitlePrefix : str
            strip title prefix when present; defaults to none
    
    ***/
    
    var pages = $0 ?? $pages ?? page.subpages;
    if(pages is str) let pages = wiki.getpage(pages).subpages;
    if(pages is map) let pages = map.values(pages);
    var sort = $1 ?? $sort ?? 'title';
    var reverse = $2 ?? $reverse ?? false;
    var limit = $3 ?? $limit;
    var liststyle = $4 ?? $style ?? 'numbers';
    var striptitleprefix = $5 ?? $striptitleprefix;
    
    // sort pages list depending on sort order
    switch(sort) {
    case 'updated':
        let pages = [ p .. { sortkey: date.format(d, 'yyyy-MM-dd'), sortlabel: 'updated on ' .. date.format(d, 'MMM d, yyyy') } foreach var p in pages, var d = p.date ];
    case 'created':
        let pages = [ p .. { sortkey: date.format(d, 'yyyy-MM-dd'), sortlabel: 'created on ' .. date.format(d, 'MMM d, yyyy') } foreach var p in pages, var d = p.revisions[0].date ];
    case 'viewcount':
        let pages = [ p .. { sortkey: num.format(p.viewcount, '0000000000'), sortlabel: num.format(p.viewcount, '#,##0') .. ' views' } foreach var p in pages ];
    case 'title':
    default:
        let pages = [ p .. { sortkey: p.title, sortlabel: nil } foreach var p in pages ];
    }
    
    // determine list style
    var listelem;
    switch(string.tolower(liststyle)) {
    case 'bullets':
        let listelem = 'ul';
    case 'numbers':
    default:
        let listelem = 'ol';
    }
    
    // check if there is at least one page to show
    if(#pages) {
        let pages = list.sort(pages, 'sortkey', reverse);
        <font size="-1">
            <(listelem)>
                foreach(var p in pages where limit ? (__count < limit) : true) {
                    <li> 
                        var title = p.title;
                        if(striptitleprefix && string.startswith(p.title, striptitleprefix, true)) {
                            let title = string.trim(string.substr(p.title, #striptitleprefix));
                        }
                        web.link(p.uri, title);
    
                        // check if there is a label to show
                        if(p.sortlabel) {
                            <span style="color: rgb(128, 128, 128); font-size: smaller;">
                                ' ('; p.sortlabel; ')';
                            </span>
                        }
                    </li>
                }
            </>
        </font>
    }
    

    Disclaimers

    None.

    Was this page helpful?
    Tag page
    Viewing 5 of 5 comments: view all
    Would it be possible to use this to list say the 10 oldest pages of the entire wiki? That would allow the content to be monitored and have someone assigned to ensure the oldest stuff is kept up-to-date
    Posted 15:50, 30 Sep 2009
    @wayne_g listpages is only responsible for listing the pages, not enumerating them; so you'll need another method for finding the 10 oldest pages
    Posted 17:12, 4 Oct 2009
    Our users have been adding numbers to page paths to force artifical sorting using wiki.tree. With ListPages they can now resort just by changing names rather than by using page move - which they love. They asked me if it was possible to remove the numbers from the titles - so I made a minor code tweak to your ListPages. Its a minor code tweak, but wondered if you would like the update to add here? Allows the stripping of the first X characters from the Title before displaying. Example: 01. General; 02. History; 03. Current Status will become General; History; Current Status if you add "stripStartChars: 4"
    Posted 11:20, 8 Oct 2009
    Why doesn't this code display the 20 most recently created wiki pages throughout the entire wiki site?
    ListPages{ pages: wiki.getpage("wiki_root").subpages, sort: "created", reverse: true, limit: 20 }
    where "wiki_root" is the name of my wiki site? edited 09:42, 1 Jun 2010
    Posted 09:40, 1 Jun 2010
    I can't seem to get this to work. I get a "pre, line 85, column 1: invalid XmlNode" error when saving the template. edited 00:43, 8 Jun 2010
    Posted 00:36, 8 Jun 2010
    Viewing 5 of 5 comments: view all
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by