Skip to main content
MindTouch Success Center

Show a list of recently modified articles with a specific tag (TCS)

Overview

This tutorial uses DekiScript to dynamically list out the ten most recent articles that have been tagged with a specific tag.  You may use this tutorial to display a dynamic list of draft articles or as a way to display featured articles on your homepage. 

Goal

After completing this tutorial you will have the ability to render dynamic lists of targetted content for your users.  While other tutorials focus on the activity or popularity of an article, this tutorial allows you to define the list criteria.  

Creating your template

In order to get started you will first need to create a new MindTouch Template.  You can accomplish this by going to the Tools menu and selecting Templates (Tools > Templates).  Once there you will need to create a new template where you can add the DekiScript to display your list of tagged articles.  Use the following instructions to create a new template:

  1. Go to Tools > Templates (/Template:)
  2. Click New Page
  3. Double Click Blank Page
  4. Give your new page a title (e.g. TaggedArticlesWidget*)

* For this example we will assume that your template is located at /Template:TaggedArticlesWidget. 

Adding the DekiScript

Now that you have created a new template, you will need to add in the DekiScript to display the list of tagged articles.  Use the following steps to accomplish this:

  1. Go to your TaggedArticlesWidget template
  2. Make sure the editor is loaded, if it isn't click Edit page
  3. In the editor click the Insert menu
  4. Select DekiScript

  1. Once you have added a DekiScript block you will need to paste the following DekiScript into it
var query = "tag:stage:draft";
var pages = wiki.getSearch(query, 10, "-date");

<div class="widget-tagged-articles">
    <ul>
        foreach (var pg in pages)
        {
            <li>
                <a href=(pg.uri)>pg.title</a>
                <span class="date">
                    "( edited ";
                        date.format(pg.date,"ddd MMM dd, yyyy");
                    " )"
                </span>
            </li>
        }
    </ul>
</div>
  1. Modify the query to search for the tag that you need (i.e.  tag:stage:draft,  tag:hotlist,  tag:tutorial,  tag:featured)
    • You can see the query in the 1st line of the code, it looks like this:
       

File:01MindTouch_Help_Center/Developer_Guide/DekiScript/Showing_a_list_of_recently_modified_articles_with_a_specific_tag/search_query_highlighted_dekiscript.png
 

  1. Click Save and move to the next step in the tutorial

Customizing the Look & Feel

Now that you have created your template and added the DekiScript you might want to customize the way it looks.  If you don't care about how it looks you can opt to skip this section and move to the next step in the tutorial. 

In order to change the look and feel you will need to add CSS to the Template.  I will provide some CSS to get your started but you can modify it in the future however you see fit.   Use the following steps:

  1. Go to your TaggedArticlesWidget template
  2. Make sure the editor is loaded, if it isn't click Edit page
  3. Go to the bottom of the page.  If the cursor only shows up in the DekiScript block just push Shift Enter to escape it. 
  4. In the editor click the Insert menu
  5. Select CSS

  1. Once you have created the CSS block you will need to paste the following CSS into it
.widget-tagged-articles .date{
    margin:0 0 0 10px;
    font-size:10px;
    color:#999;
}
  1. Click Save and move on to the next step in the tutorial

Adding your template to a page

Now that your template is complete, you're ready to embed it in a MindTouch article.  Most users will find this information valueable on the homepage of your site.  Use the instructions below to embed your TaggedArticlesWidget template to a MindTouch page:

  1. Go to the page you want to embed the widget on
  2. Click Edit page
  3. Locate where you want to add the widget (it can be in a table cell if you want)
  4. Add the following DekiScript*
template("TaggedArticlesWidget");
  1. Click Save

* For this example we will assume that your template is located at /Template:TaggedArticlesWidget. 

Demo

*There is a known issue with this tutorial returning duplicate results. This issue is currently being resolved.
  • Was this article helpful?