Umbraco 7 Tag and Sorting Tags in to Alphabetical Order Using a Dictionary
Umbraco 7 Tag and Sorting Tags in to Alphabetical Order Using a Dictionary:
<ul>
@{
Dictionary<string, int> tagsList =
new Dictionary<string, int>();
}
@foreach (var c in CurrentPage.Children())
{
if(c.HasValue("tags"))
{
foreach (var item in c.GetPropertyValue<string[]>("tags"))
{
if (!tagsList.ContainsKey(item))
{
tagsList.Add("" + item, 1);
<!--<p>@item</p>-->
}
}
}
}
@{
var ordered = tagsList.OrderBy(x => x.Key);
foreach(var i in ordered)
{
<li class="filterLink"><a href="@i.Key">@i.Key</a></li>
}
<!--<li class="filterLink"><a href="">item</a></li>-->
}
</ul>
<ul>
@{
Dictionary<string, int> tagsList =
new Dictionary<string, int>();
}
@foreach (var c in CurrentPage.Children())
{
if(c.HasValue("tags"))
{
foreach (var item in c.GetPropertyValue<string[]>("tags"))
{
if (!tagsList.ContainsKey(item))
{
tagsList.Add("" + item, 1);
<!--<p>@item</p>-->
}
}
}
}
@{
var ordered = tagsList.OrderBy(x => x.Key);
foreach(var i in ordered)
{
<li class="filterLink"><a href="@i.Key">@i.Key</a></li>
}
<!--<li class="filterLink"><a href="">item</a></li>-->
}
</ul>
Comments
Post a Comment