Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Lex Godthelp 24 posts 106 karma points
    Jul 06, 2015 @ 16:05
    Lex Godthelp
    0

    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?

  • Lex Godthelp 24 posts 106 karma points
    Jul 06, 2015 @ 22:25
    Lex Godthelp
    0

    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?

       @using  Our.Umbraco.Vorto.Extensions
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{var startNodeId = 1115;}
    @if (startNodeId != null && @CurrentPage.HasValue("tags"))
    {
        @* 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){
                    string[] itempageTags = @item.GetPropertyValue("tags").Split(',');
                    <div>
                        @foreach(var itempageTag in itempageTags){
                                @itempageTag
                                @currentpageTag
                                <article class="datasheet">Show something</article>
                        }
                    </div>
                }
            </div>
        }   
    }
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 07, 2015 @ 07:06
    Dennis Aaen
    0

    Hi Lex,

    What if you do something like this would this work for you.

    @foreach(var itempageTag in itempageTags.Where("Visible").Where(itemPageTag == currentPageTag)){  
    
    }
    

    Hope this helps,

    /Dennis

  • Lex Godthelp 24 posts 106 karma points
    Jul 07, 2015 @ 09:50
    Lex Godthelp
    0

    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)

    @using  Our.Umbraco.Vorto.Extensions
    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{var startNodeId = 1115;}
    @if (startNodeId != null && @CurrentPage.HasValue("tags"))
    {
    
        @* 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){
                    string[] itempageTags = @item.GetPropertyValue("tags").Split(',');
                    <div>
                        @foreach(var itempageTag in itempageTags){  
                            if(itempageTag.Any()){
                                foreach(var itemswithTag in itempageTag.Where(itempageTag == currentpageTag)){
                                    <article class="datasheet">123</article>
                                }
                            }
                        }
                    </div>
                }
            </div>
        }
    }
    
  • Lex Godthelp 24 posts 106 karma points
    Jul 09, 2015 @ 08:57
    Lex Godthelp
    0

    Okay guys,

    It took me a long time but here it is:

        @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?

    *Lex

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies