Created
October 27, 2017 09:49
-
-
Save ps-team/3ec05852aedb45a31992c520828ef0c2 to your computer and use it in GitHub Desktop.
A 'maintenance' razorview - displays an alphabetical list of all used template types in a site with a page count for each template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using Contensis.Framework.Web | |
@{ | |
@* | |
- this is more of a 'maintenance' razorview | |
- displays an alphabetical list of all used template types in a site with a page count for each template | |
*@ | |
<h2>List of all used templates with page count</h2> | |
// get all web page nodes in the site | |
NodeFactory nf = new NodeFactory(); | |
IEnumerable<ContentNode> nodes = ((FolderNode)nf.Load("/")).Descendants<ContentNode>().Where(n => n.IsWebPage); | |
// reference to know how many pages we are dealing with | |
<p>Total page count : @nodes.Count()</p> | |
// sorted set is used to store unique templates names in alphabetical order | |
// for each page, get its template type and add it to the sorted set | |
SortedSet<string> templateTypes = new SortedSet<string>(); | |
foreach(ContentNode node in nodes) | |
{ | |
templateTypes.Add(node.Type); | |
} | |
// variable used for sanity check | |
int globalCount = 0; | |
<hr /> | |
<table> | |
@{ | |
// for each template type... | |
foreach(string templateType in templateTypes) | |
{ | |
// ...get the number of pages that is using it | |
int count = nodes.Where(x => x.Type == templateType).Count(); | |
// render data back to the page that is in a useful form | |
<tr> | |
<td>@templateType</td> | |
<td>@count</td> | |
</tr> | |
// update sanity check | |
globalCount = globalCount + count; | |
} | |
} | |
</table> | |
<hr /> | |
// sanity check - this value should be the same as the above @nodes.Count value | |
<p>Sanity check page count : @globalCount</p> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment