Comparing tags between CurrentPage and all childrens of a node
Hi Guys,
I want to compare tags between a currentpage and all children of node 1115 using Razor. If a child has one or more tags that equal one or more tags of the currentpage, it should be shown. Can anyone steer me in the right direction?
@using Our.Umbraco.Vorto.Extensions
@inherits Umbraco.Web.Macros.PartialViewMacroPage
@{var startNodeId = 1115;}
@if (startNodeId != null && @CurrentPage.HasValue("tags"))
{
bool showSelectionpage = false;
@* Get the starting page *@
var startNode = Umbraco.Content(startNodeId);
var selection = startNode.Children.OrderBy("responseitempublicatiedatum desc").Where("responseitemcontenttype == @0","Datasheet");
@* Get the tags of the currentpage *@
string[] currentpageTags = CurrentPage.tags.Split(',');
@* Define variable for selectionpage tags page *@
foreach(var currentpageTag in currentpageTags){
<div class="contentbase">
<h2>Related datasheets</h2>
@foreach(var item in selection){
showSelectionpage=false;
string[] itempageTags = @item.GetPropertyValue("tags").Split(',');
<div>
@foreach(var itempageTag in itempageTags){
if (currentpageTags.Contains(itempageTag)){
showSelectionpage = true;}
}
@if(showSelectionpage){
IPublishedContent itemv = item;
<article class="datasheet">
Show something
</article>
}
</div>
}
</div>
}
}
It doesn't work quite like it should, because its does a for each for each tag the currentpage tag has. This works fine for when a page just has one tag, but when there's more. it should only make one list and not add doubles. Any suggestions on this?
Comparing tags between CurrentPage and all childrens of a node
Hi Guys,
I want to compare tags between a currentpage and all children of node 1115 using Razor. If a child has one or more tags that equal one or more tags of the currentpage, it should be shown. Can anyone steer me in the right direction?
Getting close, i can feel it. I can now show both the tags from the currentpage and the tags of the selection items. But how do i compare them?
Hi Lex,
What if you do something like this would this work for you.
Hope this helps,
/Dennis
Hi Dennis,
Thanks for your response. Still have not got it working:
I'm currently here but getting an error on the
.Where(itempageTag == currentpageTag)
Okay guys,
It took me a long time but here it is:
It doesn't work quite like it should, because its does a for each for each tag the currentpage tag has. This works fine for when a page just has one tag, but when there's more. it should only make one list and not add doubles. Any suggestions on this?
*Lex
is working on a reply...