Skip to main content
MindTouch Success Center

Display a list of popular pages

Embed a custom-styled list of the top ten popular articles into a MindTouch page.

Part 1: Create template

  1. Navigate to Dashboard > Content Management > Template Directory.
  2. From the MindTouch Toolbar, select New.
  3. Enter a name for the template in the Template:Page Title field, for example, "Popular Pages".
  4. From the Editor Toolbar, select Style > DekiScript.
  5. In the Enter Dekiscript field, paste the following DekiScript code:
    var uri = site.api & 'pages/popular' & { limit: 10 };
    var api = wiki.api(uri);
    
    <div class="widget-popular">
        <ul>
        foreach(var pg in api['page'] ) {
            <li>
                web.link(pg / 'uri.ui', pg / 'title');
                var viewcount = num.cast(pg / 'metrics/metric.views');
                <span class="viewcount">
                    " (";
                    num.format(viewcount,"###,###,###");
                    " views)";
                </span>
            </li>
        }
        </ul>
    </div>
    
  6. To customize the style of the template (optional), select Style > CSS from the Editor Toolbar and enter custom CSS into the field. For example:
    .widget-popular .viewcount {
        margin:0 0 0 10px;
        font-size:10px;
        color:#999;
    }
  7. Click Save and you will see the DekiScript block and CSS block (optional) in view mode.
    File:01MindTouch_Help_Center/Developer_Guide/DekiScript/Adding_a_list_of_Popular_Pages/popular_pages_code_example.png

Part 2: Embed template on MindTouch page

  1. Navigate to the page where you want the template embedded and open it in Edit Mode.
  2. Place your cursor in the desired page location and select Style > DekiScript.
  3. In the Enter Dekiscript field, paste the following DekiScript code, making sure that the text in quotes matches your template URL:
    template("Popular_Pages");
  4. Click Save.

Example with page view count

 

  • Was this article helpful?