Friday, 15 July 2011

Umbraco Razor c# Listing unique tags -



Umbraco Razor c# Listing unique tags -

i have been trying create blog using umbraco v6 using razor.

this first umbraco project still getting grips things have managed of working how want list tags in side widget.

so far have -

@{ var blogitems = umbraco.content("1188").children.where("visible"); foreach(var blog in blogitems) { var tagsplit = blog.tags.split(','); foreach(var tag in tagsplit) { <li> <a href="/blog/?@tag">@tag</a> </li> } } }

the problem lists tags duplicating many of them. have tried utilize .distinct on tagsplit variable returns error.

any ideas?

.distinct() should work, since it's not, quick , dirty solution is:

@{ var blogitems = umbraco.content("1188").children.where("visible"); foreach(var blog in blogitems) { var tagsplit = blog.tags.split(','); var usedtags=new list<string>(); foreach(var tag in tagsplit) { if(!usedtags.contains(tag)){ <li> <a href="/blog/?@tag">@tag</a> </li> } usedtags.add(tag); } } }

c# razor umbraco blogs umbraco-tags

No comments:

Post a Comment