Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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?
Something like this?
var imgSrc = "";if (@project.HasValue("photos")) { imgSrc = @project.photos.mediaItem.Image.umbracoFile;}
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
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"/>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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?
Something like this?
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
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"/>
is working on a reply...