Popular pages list in DekiScript
- Applies to:
- All MindTouch Versions
- Role required:
- Draft Contributor
Embed a custom-styled list of the top ten popular articles into an Expert page.
Part 1: Create template
- Navigate to Site Tools > Dashboard > Site Administration > Template Directory.
- From the Expert Toolbar, select New.
- Enter a name for the template in the Template:Page Title field, for example, "Popular Pages".
- From the Editor Toolbar, select Style > DekiScript.
- In the Enter Dekiscript field, paste the following DekiScript code:
01
var
uri
= site.api &
'pages/popular'
& { limit: 10 };
02
var
api = wiki.api(
uri
);
03
04
<div class=
"widget-popular"
>
05
<ul>
06
foreach
(
var
pg
in
api[
'page'
] ) {
07
<li>
08
web.link(pg /
'uri.ui'
, pg /
'title'
);
09
var
viewcount =
num
.cast(pg /
'metrics/metric.views'
);
10
<span class=
"viewcount"
>
11
" ("
;
12
num
.format(viewcount,
"###,###,###"
);
13
" views)"
;
14
</span>
15
</li>
16
}
17
</ul>
18
</div>
- To customize the style of the template (optional), select Style > CSS from the Editor Toolbar and enter custom CSS into the field. For example:
1
.widget-popular .viewcount {
2
margin
:
0
0
0
10px
;
3
font-size
:
10px
;
4
color
:
#999
;
5
}
- Click Save and you will see the DekiScript block and CSS block (optional) in view mode.
Part 2: Embed template on Expert page
- Navigate to the page where you want the template embedded and open it in Edit Mode.
- Place your cursor in the desired page location and select Style > DekiScript.
- In the Enter Dekiscript field, paste the following DekiScript code, making sure that the text in quotes matches your template URL:
1
template(
"Popular_Pages"
);
- Click Save.
Example with page view count