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 03, 2015 @ 09:49
    Lex Godthelp
    0

    Comparing ID of current page with selection ID

    Hi guys,

    Quick question. I want to compare all id's of the children a startnode with the currentpage. If the id's match, it should not show. I have this but somehow it doesn't seem to work:

    .Where("pageId != @Model.Id")
    

    Any suggestions?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 03, 2015 @ 10:08
    Dennis Aaen
    0

    Hi Lex.

    What if you do something like this.

    .Where("pageId != @CurrentPage.Id")
    

    If this not working would it be possible for you to share the whole code that you have.

    Hope this helps, and works

    /Dennis

  • Lex Godthelp 24 posts 106 karma points
    Jul 03, 2015 @ 10:52
    Lex Godthelp
    0

    Hello Dennis,

    Thank you for your suggestion but it does not seem to work. This is my full code:

    @{var startNodeId = 1115;}
    @if (startNodeId != null)
    {
        @* Get the starting page *@
        var startNode = Umbraco.Content(startNodeId);
        var selection = startNode.Children.OrderBy("responseitempublicatiedatum desc").Where("responseitemcontenttype != @0","Datasheet").Where("pageId != @CurrentPage.Id"); @* Nog vergelijken met @Model.Id *@
    
    if (selection.Any()){
    <div class="contentbase">
        <h2>Related @Model.Content.GetVortoValue("paginatitel") downloads</h2>
        @foreach(IPublishedContent item in selection){
            <article class="datasheet">
                <a href="@item.Url" title="@(item.GetVortoValue<string>("paginatitel"))"><h3>@(item.GetVortoValue<string>("paginatitel"))</h3></a>
                <div class="datasheetcontent2">
                    <p>@(item.GetVortoValue<string>("responseitemkortesamenvatting"))</p>
                </div>
                <div class="datasheetimage">
                    <img src="@item.GetPropertyValue("responseitemimageurl")" alt="Lees verder over Enterprise Mobility for Dummies" />
                </div>
                <div class="datasheetdownload">
                    <div class="floatright">
                        <a href="@item.Url" target="_blank" title="@(item.GetVortoValue<string>("paginatitel"))" class="downloadbutton">Download</a>
                    </div>
                </div>
            </article>
        }
        </div>
        }
    }
    

    Note: It does not give an error, but it returns empty.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 03, 2015 @ 11:56
    Dennis Aaen
    0

    Hi Lex

    Try to see if this will works for you then.'

    var selection = startNode.Children.OrderBy("responseitempublicatiedatum desc").Where("responseitemcontenttype != @0","Datasheet").Where("Id != @CurrentPage.Id");
    

    Edit: I have just edit my post. I was wrong you are in dynamic Razor context.

    Hope this helps,

    /Dennis

  • Lex Godthelp 24 posts 106 karma points
    Jul 03, 2015 @ 12:20
    Lex Godthelp
    0

    Hello Dennis,

    Thank you for your response. Using Id gives me a error loading Partial View Script. Using nodeId or pageId just returns an empty Script where it should show something.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 03, 2015 @ 19:45
    Dennis Aaen
    100

    Hi Lex,

    I have the change to have a look at it again. And I have created a simple edition of you code that should do what you are after.

    I think the easiest way is to create a variable that holds the ID of the current page.

    @{ 
    
        var startNodeId = 1073; 
        var currentPageId = CurrentPage.Id;
     }
    @if (startNodeId != null)
    {
        @* Get the starting page *@
        var startNode = Umbraco.Content(startNodeId);
        var selection = startNode.Children.Where("Visible").Where("Id != @0",currentPageId);
    
        if (selection.Any())
        {
            <ul>
                @foreach (var item in selection)
                {
                    <li>
                        <a href="@item.Url">@item.Name</a>
                    </li>
                }
            </ul>
        }
    }
    

    Remember to change startNodeId to an id of 1115

    Hope this helps,

    /Dennis

  • 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