Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    Mar 03, 2015 @ 23:29
    James
    0

    Portfolio Item Partial

    Hello,

     

    I am currently working on a 7.2 website.

     

    My site structure is

     

    Home>

    Portfolio >

    Portfolio Items 

     

    I am trying to create a partial view for the footer that selects the last 4 portfolio items. It is going to be rendered on the master layout.

     

    How can i ensure that when i select the 4 items, they will be displayed even when i am on a portfolio item page?

     

    Currently I have:

     @foreach (var page in CurrentPage.DescendantsOrSelf("PortfolioItem").Take(4))

        {

    }

     

    This works great until I am on a portfolio Item page, then it only sees the item I am on.

     

    Thanks

     

    Kind regards,

     

    J

     

  • mike 90 posts 258 karma points
    Mar 03, 2015 @ 23:40
    mike
    100

    Use the umbraco helper instead.

    var items = Umbraco.TypedContent(portfolioId).Children

  • James 251 posts 1169 karma points
    Mar 03, 2015 @ 23:47
    James
    0

    Genius thank you :)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Mar 03, 2015 @ 23:55
    Dennis Aaen
    0

    Hi James,

    You could also do it like this, I think this is a more safer way to do it, because if the user deletes the node, and created it again then it will get a new id, and your code will throw an error when you are bind it to and specific id.

    @foreach (var page in CurrentPage.AncestorOrSelf(1).Descendants("PortfolioItem").Take(4)){
    //Do some stuff
    }

    Hope this helps,

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft