Copied to clipboard

Flag this post as spam?

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


  • Robert J. Bullock 386 posts 405 karma points
    Nov 27, 2012 @ 21:59
    Robert J. Bullock
    0

    Retrieve first value of Multinode Tree Picker

    Is there a simple way to get the value of the FIRST item in a multinode tree picker in Razor? Could've sworn I've done something like this before:

    foreach(var project in item.Children.Take(1)){
     dynamic mediaItem = project.photos.First();
     <div class="featured-project">
       <a href="@project.Url" class="fancybox"><img src="@Model.MediaById(@mediaItem.InnerText)"
    alt="@project.title"/></a>
      <h2>@project.title</h2>
      <h3>@project.location</h3>
     </div>

    Any suggestions?

  • Matthias 87 posts 173 karma points
    Nov 28, 2012 @ 13:55
    Matthias
    0

    Something like this?

    var imgSrc = "";
    if (@project.HasValue("photos")) {
    imgSrc = @project.photos.mediaItem.Image.umbracoFile;
    }
  • Richard Terris 273 posts 715 karma points
    Nov 28, 2012 @ 14:35
    Richard Terris
    0

    You could use uQuery, which is now in the Umbraco namespace, to get a list of the selected items

    string csv = uQuery.GetCurrentNode().GetProperty<string>("myProperty");

    List<Node> selectedNodes = uQuery.GetNodesByCsv(csv);

    foreach(var project in selectedNodes.Take(1))

    {
    //do stuff

    if you're only taking 1 item then it should be the first item in the list anyway

  • Robert J. Bullock 386 posts 405 karma points
    Nov 28, 2012 @ 18:10
    Robert J. Bullock
    0

    This worked:

    @foreach(var photo in project.photos){
       if(photo.IsFirst()){
    var photoURL = photo.InnerText;
    <img src="@Model.MediaById(photoURL).umbracoFile" alt="@project.title"/>
    }
    }

    But it seems a bit verbose to me... I would have just preferred:

    <img src="@Model.MediaById(Model.photos.Take(1)).umbracoFile" alt="@project.title"/>

Please Sign in or register to post replies

Write your reply to:

Draft