I have been trying to access a property of my current page and am struggling with the XML manipulation. The property is of datatype Related links with Media and am running Umbraco 6.1.0.
I can get the property and it contains an XML string as follows:
I can get to the link element by using links.link and get to attributes correctly using links.link.title. The issue is when I do links.link.link it returns me exactly the same as links.link - is there any way around that without me having to removing fields?
Also is there a way to get the count of how many link elements are within links?
That's great! If you did want to get a count of the elements, you should able to do that by using .Count on the DynamicXml object. e.g. if you were using the Mvc Dynamic sample:
if(CurrentPage.HasValue("relatedLinks") && CurrentPage.relatedLinks.Any()){ if (CurrentPage.releatedLinks.Count() > 4){
<ul>
@foreach (var item in CurrentPage.relatedLinks){
var linkUrl = (item.type.Equals("internal")) ? @Umbraco.NiceUrl(int.Parse(item.link)) : item.link;
var linkTarget = (item.newwindow.Equals("1")) ? " target=\"_blank\"" : String.Empty;
<li><a href="@linkUrl"@Html.Raw(linkTarget)>@item.title</a></li>
}
</ul> }
}
Additionaly, I would recommend you check out using uComponents Multi-URL Picker, I has a lot better UI that the Core Related Links picker and I think it will be included in Umbraco v6.2 Core. http://ucomponents.org/data-types/multi-url-picker/
I know this thread is a few months old but am having a slight problem with the relatedLinks data type.
I have it set up and can list out all the links no problem. Each link (all internal) has a "mainImage" property, and what I want to do is list out the images of the related items, but I can't figure out how to do that, and I can't see anywhere in the documentation that says how.
I tried to get the node ID of each link but it caused an error so commented it out. The item.Media() in the src of the img tag also doesn't work. Any ideas?
I tried using the Multi URL picker from uComponents but had great difficulty counting the number of related links so changed it to this (which works better apart from this).
So am I right in saying that each node in the related links is internal and each of those nodes has a property called MainImage and that is what you are after?
Razor and Related links with Media
Hello,
I have been trying to access a property of my current page and am struggling with the XML manipulation. The property is of datatype Related links with Media and am running Umbraco 6.1.0.
I can get the property and it contains an XML string as follows:
The type of the string is dynamicXML.
I can get to the link element by using links.link and get to attributes correctly using links.link.title. The issue is when I do links.link.link it returns me exactly the same as links.link - is there any way around that without me having to removing fields?
Also is there a way to get the count of how many link elements are within links?
Any help would be greatly appreciated.
Regards
Andy
Hey Andy,
Did you take a look at the sample code on the the Related Links documentation page here?
Thanks,
Jeavon
Hi Jeavon,
Thanks for pointing that out - I'd looked at the Related Links with media and not the normal Related links - all working now!
Andy
Hi Andy,
That's great! If you did want to get a count of the elements, you should able to do that by using .Count on the DynamicXml object. e.g. if you were using the Mvc Dynamic sample:
Additionaly, I would recommend you check out using uComponents Multi-URL Picker, I has a lot better UI that the Core Related Links picker and I think it will be included in Umbraco v6.2 Core. http://ucomponents.org/data-types/multi-url-picker/
Thanks,
Jeavon
Hello,
I know this thread is a few months old but am having a slight problem with the relatedLinks data type.
I have it set up and can list out all the links no problem. Each link (all internal) has a "mainImage" property, and what I want to do is list out the images of the related items, but I can't figure out how to do that, and I can't see anywhere in the documentation that says how.
Here is my code:
I tried to get the node ID of each link but it caused an error so commented it out. The item.Media() in the src of the img tag also doesn't work. Any ideas?
I tried using the Multi URL picker from uComponents but had great difficulty counting the number of related links so changed it to this (which works better apart from this).
Any ideas?
Hi John,
So am I right in saying that each node in the related links is internal and each of those nodes has a property called MainImage and that is what you are after?
If I'm correct then I think this:
Jeavon
Ah I can see how your getting the id's now. I wasn't aware about the .link property.
Thanks for your help.
is working on a reply...