Template:WhatsPopular

    Table of contents
    No headers
    /* WARNING
     * WARNING: this community-contributed template is not fit for production use as it performs a complete db-scan with every invocation
     * WARNING
     */
    
    // Parameters:
    //   title: The title text
    //   Path:  pathe to the starting page
    //   max:  Maximum number of items to list
    //   depth:  The level of sub page to evaluate
    //   reverse:  Reverse to sort order
    //   blockstyle:  Any valid in-line styles.  Affects container that wraps entire template
    //   titlestyle:  Any valid in-line styles.  Affects the title section
    //   bodystype:   Any valid in-line styles.   Affects the body section
    /*
      In a dekiscript block:
        WhatsPopular{ title: 'My Popular Pages', 
                   path: '/resources', 
                   max: 5, 
                   depth: 2, 
                   reverse: true, 
                 };
    
    Vesion History: 1.0 - Initial release
                    1.0.a - Changed from using div id's to div classes
                    1.1 - (neilw) Changed to using @pageid to find the pages from wiki.tree()
      
    */
    
    var ttl = ($0 ?? args.title ?? 'Whats New!');
    var path = ($1 ?? args.path ?? page.path);
    var maxnum = ($2 ?? args.max ?? 10);
    var depth = ($3 ?? args.depth ?? 10);
    var reverse = ($4 ?? args.reverse ?? true);
    var blockstyle = ($5 ?? args.blockstyle ?? '');
    var titlestyle = ($6 ?? args.titlestyle ?? '');
    var bodystyle = ($7 ?? args.bodystyle ?? '');
    
    
    var pageviews = 0;
    var pagelist = [];
    var pxml = wiki.tree(path,depth);
    
    foreach(var pid in xml.list(pxml, "//a/@pageid")) {
       let p = wiki.getpage(num.cast(pid));
       let pagelist ..= [ {title: p.title, uri: p.uri, viewcount: p.viewcount } ];
    }
    
    let pagelist = list.sort(pagelist, 'viewcount', reverse);
    
    <div class="whtspop" style=(blockstyle)>
    
        <div class="whtspoptitle" style=(titlestyle)>
            ttl;
         </div>
    
         <div class="whtspopbody" style=(bodystyle)>
    
            foreach(var p in pagelist) {
              if(__count >= maxnum) {break;}
    
                if(p.uri) {
                   web.link(p.uri, p.title); <span style="font-size: x-small;">;' - (' ..num.format(p.viewcount,'##,#') ..' Views)'; </span> <br/>;
              }
    
            }
                      
        </div>
    
    </div>
    
    
    // styles
    <html>
       <head>
          <style type="text/css">"
    
              div.whtspop {
                 width: 100%;
             }
    
              div.whtspoptitle {
                 background-color: rgb(234, 234, 234);
                 text-align: center;
                 padding: 2px;
                 font-weight: bold;
                 font-size: 16px;
                 border-style: outset; 
              }
        
              div.whtspopbody {
                 background-color: #FFF;
                 padding: 2px;
                 border-style: solid;
                 border-width: 1px;
                 text-align: left;
              }
           "
           </style>
       </head>
    </html>
    Tag page
    You must login to post a comment.

    Copyright © 2011 MindTouch, Inc. Powered by