Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Andrew Bright 84 posts 244 karma points
    Dec 10, 2020 @ 20:50
    Andrew Bright
    0

    Related Links not including properties

    I am using Umbraco.RelatedLinks2 example grid below: enter image description here

    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"
      }
    ]}
    

    Please could someone advise on this please?

    Thanks

    Andrew

  • Amir Khan 1282 posts 2739 karma points
    Dec 10, 2020 @ 22:13
    Amir Khan
    0

    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.

  • Andrew Bright 84 posts 244 karma points
    Dec 10, 2020 @ 23:11
    Andrew Bright
    0

    Thanks for the response but using :

    @if (Model.Content.RelatedLinks != null && 
    Model.Content.RelatedLinks.Count() > 0)
    { 
    var typedRelatedLinksConverted = 
    Model.Content.GetPropertyValue<RelatedLinks>("relatedLinks");
    
    foreach (var item in typedRelatedLinksConverted)
    {
        var linkUrl = (item.IsInternal) ? Umbraco.NiceUrl(nodeId) : item.Link;
    }
    

    Proves to be no different I am afraid and this is including @using Umbraco.Web.Models

  • Carlos Mosqueda 240 posts 431 karma points
    May 04, 2021 @ 17:55
    Carlos Mosqueda
    0

    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.

Please Sign in or register to post replies

Write your reply to:

Draft