I am using Umbraco.RelatedLinks2 example grid below:
The first two links are internal pages the second of which is unpublished and the last two links are external. I firstly need to identify internal pages and exclude those that are unpublished to avoid 404 and secondly check external links are not null.
backend code snippet:
foreach (var item in Model.Content.GetPropertyValue<JArray>("relatedLinks", true))
{
var nodeId = Model.Content.Parent.Children
// Or you could use "InvariantEquals".
.Where(x => x.Name.InvariantContains(item.Value<string>("caption")))
.Select(x => x.Id).FirstOrDefault();
var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.Value<string>("link");
bool published = false;
// Get the content parent and find the child using the related link caption as name lookup
// return if the content is published (Visible)
published = Model.Content.Parent.Children
// Or you could use "InvariantEquals".
.Where(x => x.Name.InvariantContains(item.Value<string>("caption")))
.Select(x => x.IsVisible()).FirstOrDefault();
The isInternal is always returning false and subsequently no Id is being returned either and Im not sure why see json from JArray below:
{[
{
"caption": "Check when your bin will be emptied",
"link": "/check-when-your-bin-will-be-emptied",
"newWindow": false,
"edit": false,
"isInternal": false,
"type": "external",
"title": "Check when your bin will be emptied"
},
{
"caption": "What goes in which bin",
"link": "/what-goes-in-which-bin",
"newWindow": false,
"edit": false,
"isInternal": false,
"type": "external",
"title": "What goes in which bin"
},
{
"caption": "Testing external",
"link": "http://testing.com",
"newWindow": false,
"edit": false,
"isInternal": false,
"type": "external",
"title": "Testing external"
},
{
"caption": "Testing",
"link": "testingtwo.com",
"newWindow": false,
"edit": false,
"isInternal": false,
"type": "external",
"title": "Testing"
}
]}
Related Links not including properties
I am using Umbraco.RelatedLinks2 example grid below:
The first two links are internal pages the second of which is unpublished and the last two links are external. I firstly need to identify internal pages and exclude those that are unpublished to avoid 404 and secondly check external links are not null.
backend code snippet:
The isInternal is always returning false and subsequently no Id is being returned either and Im not sure why see json from JArray below:
Please could someone advise on this please?
Thanks
Andrew
Any reason not to use the property value converter link in the docs? https://our.umbraco.com/documentation/getting-started/backoffice/property-editors/built-in-property-editors/Related-Links2
Should take care of most of those issues for you.
Thanks for the response but using :
Proves to be no different I am afraid and this is including @using Umbraco.Web.Models
Did you ever find a solution for this?
GetPropertyValue
But again, this is Umbraco 7, and they have moved onto 8 where they got rid of related links in favor of MutilUrl Picker.
But if you have a solution or I find one, I would be more than happy to find out or have any help.
is working on a reply...