Copied to clipboard

Flag this post as spam?

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


  • Dennis 33 posts 238 karma points
    Oct 26, 2015 @ 09:47
    Dennis
    0

    Get Content by alias

    I need a way to get content not by id but by alias?

    In UmbracoApiController I have a method for this: GetNodeByAlias(alias);

    How can this be accomplished from the Umbraco context?

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Oct 26, 2015 @ 10:02
    Hendy Racher
    101

    Hi Dennis,

    You could use an XPath expression with the UmbracoHelper:

    UmbracoHelper umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    

    If there are multiple content nodes with the given alias:

    IEnumerable<IPublishedContent> content = umbracoHelper.TypedContentAtXPath("//" + alias);
    

    Or if you are expecting a single result you can use:

    IPublishedContent content = umbracoHelper.TypedContentSingleAtXPath("//" + alias);
    

    HTH, Hendy

  • Dennis 33 posts 238 karma points
    Oct 26, 2015 @ 13:26
    Dennis
    0

    Thank you Hendry, that solved my problem :)

Please Sign in or register to post replies

Write your reply to:

Draft