c# - Combining tags from children in Umbraco -


i have blog section on umbraco site, want tags each blog item , combine them in list without dublicates, can use taglist filter.

i have section tags listed

<ul id="blogtags" class="inline-list">    <li class="tag-item"><a href="#">tag 1</a></li>    <li class="tag-item"><a href="#">tag 2</a></li>    <li class="tag-item"><a href="#">tag 3</a></li>    <li class="tag-item"><a href="#">tag 4</a></li> </ul> 

on blogitem doctype have field tagslist editor can input comma-separated list of tags.

so want tags blogitems , combine them list dublicates removed.

i getting blog items using:

 var blogitems = umbraco.typedcontent(model.content.id).children.where(x => x.documenttypealias == "blogitem" && x.isvisible()); 

but not sure how tags, combine , remove dublicates.

one way of doing create hashset store tags , use foreach add it.

so can like:

hashset<string> uniquetaglist = new hashset<string>();  var blogitems = umbraco.typedcontent(model.content.id).children.where(x => x.documenttypealias == "blogitem" && x.isvisible());  var tags = blogitems.select(x => x.getpropertyvalue<string>("tagslist"));  foreach(var tag in tags) {     var splittag = tag.split(',');     foreach(var singletag in splittag)     {         uniquetaglist.add(singletag);     } } 

then uniquetaglist list of tag, can use create list

<ul id="blogtags" class="inline-list">     @foreach(var tag in uniquetaglist)     {         <li class="tag-item"><a href="#">@tag</a></li>     } </ul> 

but beware if have lot of children, can take time.

so suggest checkout umbraco tag data type this:

https://shermandigital.com/blog/display-umbraco-tags-on-razor-templates/

https://shermandigital.com/blog/get-umbraco-content-by-tag/


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -