Reputation: 1
I have a RelatedLinks property in one of my pages that I need to get the links/PageIds out from in the code behind of my macro-user control.
I can get the property like this
var current = Node.GetCurrent();
Response.Write("Output: " + current.GetProperty("RelatedLinks").Value);
But the output is empty. When I debug I can see that the Value includes some list content (like tags and such) some somehow nothing is printed.
My question is how I can get the value from this property into something like a collection of hyperlink objects.
I'm new to Umbraco and I's possible that I'm missing something essential here. Getting the content of other property types (like the Content Picker) works fine.
Thanks!
Upvotes: 0
Views: 3395
Reputation: 4012
You can use this simple solution in Umbraco 7.+
Model.Content.GetPropertyValue<Umbraco.Web.Models.RelatedLinks>("relatedArticles");
this simply convert data to static type that is easy to use.
Upvotes: 1
Reputation: 1
Solved it like this:
Document doc = new Document(Node.GetCurrent().Id);
umbraco.cms.businesslogic.property.Property relatedLinks = doc.getProperty("RelatedLinks");
XmlNode relatedLinksAsXml = relatedLinks.ToXml(new XmlDocument());
However it says that the Document class is obsolete and wants me to use Umbraco.Core.Models.Content instead. But this is MVC right? I'm trying to use webforms. Tried using the Node class as described in this thread but the Property object I got returned was of the wrong type and couldn't be converted to XML.
Upvotes: 0
Reputation: 411
Try this umbraco.NodeFactory.Node.GetCurrent().GetProperty("RelatedLinks")
Upvotes: 0
Reputation: 538
What data type is your related links set to, assuming its a content picker where you are getting the id of the related page you could first create a node form your current page's id then try and get the value from that node e.g.
var current = Node.GetCurrent();
var currentPage = Model.NodeById(current.Id);
var relatedLinks = currentPage.RelatedLinks;
or
var relatedLinks = GetProperty("RelatedLinks").Value;
when you debug you should be able to see all the properties of currentpage and check your alias as well to make sure its right (generally aliases dont start with a capital by default).
Upvotes: 0