Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 22, 2015 @ 14:59
    Owain Williams
    0

    Content picker to link to a blog post

    Hi, I have a content picker on one of my document types. The plan is to pick a blog post to link to from another page outwith Articulate. When I try and display the link, all I get is the node id.

    Is it possible to link to the blog post and if so, how would I go about it.

    I'm wondering if it's possible to use the node id in some way to find the relevant blog post and popular a url.

    Thanks, Owain.

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jul 22, 2015 @ 15:00
    Shannon Deminick
    0

    how are you trying to "display the link" ?

  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 22, 2015 @ 15:04
    Owain Williams
    0

    Hi Shannon, I just tried with a the Umbraco field name.

    @Umbraco.Field("linkToRaceReport")
    

    Which brings back 1709 as the node id.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 22, 2015 @ 15:33
    Dennis Aaen
    0

    Hi Owain,

    Try to see the documentation about how to the the link url from a content picker.

    https://our.umbraco.org/Documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Content-Picker

    Hope this helps,

    /Dennis

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jul 22, 2015 @ 16:27
    Shannon Deminick
    100

    Yes, a content picker will only return an ID, that is normal thing with how Umbraco works.

    You need to take that Id and get the IPublishedContent item for it which will give you the URL:

    @{ 
      var linkedContent = 
               Umbraco.TypedContent(
                      Model.Content.GetPropertyValue("linkToRaceReport");
    
      var linkedContentUrl = linkedContent != null ? linkedContent.Url : null;
    
     }
    
  • Owain Williams 481 posts 1413 karma points MVP 7x c-trib
    Jul 22, 2015 @ 21:02
    Owain Williams
    0

    Thanks guys!

    Now have that working perfectly. Wrapped it in an If statement so it only shows if I've made a selection with the content picker as well.

        @if (CurrentPage.linkToRaceReport != null && !(CurrentPage.linkToRaceReport is Umbraco.Core.Dynamics.DynamicNull))
                    { 
      var linkedContent = 
               Umbraco.TypedContent(Model.Content.GetPropertyValue("linkToRaceReport"));
    
      var linkedContentUrl = linkedContent != null ? linkedContent.Url : null;
    <h3>Race report</h3>
    <a href="@linkedContentUrl">@linkedContent.Name</a>
    
                    }
    
Please Sign in or register to post replies

Write your reply to:

Draft