Copied to clipboard

Flag this post as spam?

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


  • Graeme 19 posts 111 karma points
    Jul 30, 2013 @ 22:36
    Graeme
    0

    accessing content picker details

    Hi I'm new to umbraco / razor and I'm struggling to get the details from a content picker property.

    I have the following snippet of code:

               @{

            var nodeIds = Model.Content.GetPropertyValue("items").ToString().Split(',');

            List<IPublishedContent> products = new List<IPublishedContent>();

     

            foreach (var nodeId in nodeIds)

    {

    if (!String.IsNullOrEmpty(nodeId))

    {

    var publishedContent = Umbraco.NiceUrl(Convert.ToInt32(nodeId));

    if (!String.IsNullOrEmpty(publishedContent) && publishedContent != "#")

    {

    products.Add(Umbraco.TypedContent(nodeId));

    }

    }

    }

            }

     

            @foreach (var product in products)

            {

                if(product != null)

                { <div class="feature fl">

    <h2>@Html.Raw(product.GetPropertyValue("displayTitle"))</h2>

                        <img class="productImage" [email protected](product.GetPropertyValue("displayTitle")) [email protected](product.GetPropertyValue("displayImage")) />  

                        </div> 

                }

            }

    Within the each product in products the <h2> element is displaying the nodeID from here I would like to retrieve the displayTitle.Name and have the wrapped in a href displayTitle.Url

    But cannot seem to get the code right any pointers would be appreciated.

    Many Thanks

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 30, 2013 @ 22:51
    Jeavon Leopold
    0

    Hi Graeme,

    You mention content picker but that only picks one item and it looks like you have multiple, are you actually using a multi node tree picker?

    Thanks,

    Jeavon

  • Graeme 19 posts 111 karma points
    Jul 30, 2013 @ 23:04
    Graeme
    0

    Hi Jeavon

    Thanks for the reply, what I have on this page is a page picker, named items, that holds the collection of product document types. From this I get a list of Products. The product document type has, amongst others, a content picker property that I'm wanting to use as a link to the product document type page itself. Hope this isn't too confusing if there's a simpler solution I'm open to suggestions. I'm not too far off at the moment I just need to get the name and url from the content picker named displayTitle

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 30, 2013 @ 23:14
    Jeavon Leopold
    0

    Ok, cool, so the property "items" is a CSV string of nodeids right?

  • Graeme 19 posts 111 karma points
    Jul 30, 2013 @ 23:19
    Graeme
    0

    In a nutshell yes, and then each of these nodeids (document type product) has a content picker property named displayTitle. Within the <h2> tag I currently have the node id but what I want is the name and also to be wrapped within the url.

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 30, 2013 @ 23:27
    Jeavon Leopold
    100

    Ok, got it, I think you need

    var displayItem = Umbraco.TypedContent(product.GetPropertyValue("displayTitle"));
    <a href="@displayItem.Url">@displayItem.Name</a>
    
  • Graeme 19 posts 111 karma points
    Jul 31, 2013 @ 10:49
    Graeme
    0

    Thanks Jeavon, works perfectly

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 31, 2013 @ 13:00
    Jeavon Leopold
    0

    Awesome!

Please Sign in or register to post replies

Write your reply to:

Draft