Copied to clipboard

Flag this post as spam?

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


  • Thomas 5 posts 95 karma points
    Nov 18, 2019 @ 06:53
    Thomas
    0

    Get url of document type

    First off I'm completely new to the world of Umbraco, and still trying to figure things out. I'm using it as a platform to learn Razor/C#, while building my portfolio.

    My issue: On my "homePage" i have a loop of "portfolioCase" i'm successfully looping a title, image, and a description from "portfolioCase". But i can't figure out how to pull the url of "portfolioCase" so that i can link to the page from the loop.

    This is my Content tree:

    -homePage
    --portfolio
    ---portfolioCase
    

    Best Regards

    Thomas

  • Morten Hartvig 5 posts 78 karma points
    Nov 18, 2019 @ 10:10
    Morten Hartvig
    1

    Hi Thomas,

    Content nodes (pages) use the IPublishedContent interface as the model (see more here) for published content. The model has a Url property you can use, e.g.:

    // To be used in the "portfolio" template
    @foreach (var caseItem in Model.Children) 
    {
        <a href="@caseItem.Url">@caseItem.Name</a> 
    }
    
  • Thomas 5 posts 95 karma points
    Nov 18, 2019 @ 10:58
    Thomas
    0

    Thanks Morten. I'll take a look at the documentation.

    Do i need to use Model.Descendant if i use it on "homePage" template?

  • Thomas 5 posts 95 karma points
    Nov 18, 2019 @ 19:15
    Thomas
    100

    I ended up just using @child.Url

    @{ var List = Model.Descendants().Where(x => x.ContentType.Alias=="portfolioCase");}  
    
    @foreach(var child in List){
    <a "href="@child.Url">Show case</a>
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft