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
I have an article document type and in that I have a section for adding related links to other articles. In the related articles section I can add links to an external site by just providing the URL or I can add a link to an internal article I wrote.
When retrieving the related articles I need to be able to determine if this is one of my internal articles or a link to another site. The best way to do this would be to just grab the document type, then do a switch on that.
How would I go about getting the document type of a property within another document type?
Here is my foreach I'm using to iterate through the related articles:
@foreach (var article in CurrentPage.relatedArticles)
// render html based on articles document type
Not sure if I'm able to even get the document type of article as I can't see that property anywhere in the debugger.
What datatype are you using to store the related articles?
Is it the built-in picker or something like https://our.umbraco.com/packages/backoffice-extensions/multi-url-picker/ ?
The RJP MultiUrlPicker surfaces a property indicating what type of link has been added, which might be helpful for you :)
I'm actually using the obsolete Related Links data type (https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/related-links)
It's an older site and there's a lot of document types that are using this data type so unfortunately I don't think I can switch :(.
Looks like you might still be able to get the link type using one of the snippets posted on that page as a base:
if (Model.Content.HasValue("relatedLinks") && Model.Content.GetPropertyValue<string>("relatedLinks").Length > 2)
@foreach (var item in Model.Content.GetPropertyValue<JArray>("relatedLinks"))
var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.Value<string>("link");
var linkTarget = item.Value<bool>("newWindow") ? "_blank" : null;
<li><a href="@linkUrl" target="@linkTarget">@(item.Value<string>("caption"))</a></li>
The helpful bit being
If it is, then you can use the id to search for the content node, if it's not then it's presumably an external link.
I forgot to explain that some of my "internal" articles are actually just links to external articles that are related to my articles. I just set them up as internal articles so I can store meta data I get from the external article in my database. So they are all considered "internal" as far as Umbraco is concerned. This means that the link generated by Umbraco for that node goes nowhere.
What I ended up doing was taking the internal id in my foreach loop and using Umbraco.Content(internalId) to get the External Article node. If it actually is a node and not just a link then the id is greater than 0. After that I could get the DocumentTypeAlias and perform my if statement.
It's kind of a mess but it works.
Thanks for the help Laura!
Code for anyone interested:
var internalId = item.Value<int>("internal");
MyMetaInformationModel externalNewsArticle = null;
if (internalId > 0)
var node = Umbraco.Content(internalId);
if (node.DocumentTypeAlias == "externalArticleNews")
externalNewsArticle = JsonConvert.DeserializeObject<MyMetaInformationModel>(node.GetPropertyValue<string>("externalUrl"));
if (externalNewsArticle != null)
var linkUrl = externalNewsArticle.Url;
// got the external url YAY!
// just a regular article
Awesome :) glad you got it working!
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted