Copied to clipboard

Flag this post as spam?

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


  • Flash 9 posts 62 karma points
    May 13, 2017 @ 18:34
    Flash
    0

    Related Links

    Having some issues returning/parsing the return value from the RelatedLinks picker. item.pageRelatedLinks is returning the following value:

    "[\r\n  {\r\n    \"caption\": \"Laboramus\",\r\n    \"link\": 1123,\r\n    \"newWindow\": false,\r\n    \"edit\": false,\r\n    \"isInternal\": true,\r\n    \"type\": \"internal\",\r\n    \"title\": \"Laboramus\",\r\n    \"internal\": 1123,\r\n    \"internalName\": \"Home\",\r\n    \"internalIcon\": \"icon-home\"\r\n  },\r\n  {\r\n    \"caption\": \"Intellegam animal molestiae\",\r\n    \"link\": 1123,\r\n    \"newWindow\": false,\r\n    \"edit\": false,\r\n    \"isInternal\": true,\r\n    \"type\": \"internal\",\r\n    \"title\": \"Intellegam animal molestiae\",\r\n    \"internal\": 1123,\r\n    \"internalName\": \"Home\",\r\n    \"internalIcon\": \"icon-home\"\r\n  }\r\n]"
    

    The error with the below code states that 'isInternal' is not valid on type 'char'. On inspection, itemLink is "91".

    Anyone any idea what is going wrong?

    @foreach (var itemLink in item.pageRelatedLinks)
                                                    {
                                                        var linkUrl = (bool)itemLink.isInternal ? umbraco.library.NiceUrl(itemLink.Value<int>("internal")) : itemLink.link;
                                                        var linkTarget = (bool)itemLink.newWindow ? "_blank" : null;
                                                        <li><a href="@linkUrl" target="@linkTarget">@itemLink.caption</a></li>
                                                    }
    
  • Flash 9 posts 62 karma points
    May 14, 2017 @ 02:08
    Flash
    101

    In case anyone else has this issue, this approach worked:

    <ul>
                       @foreach (dynamic item in JsonConvert.DeserializeObject(startNode.GetPropertyValue<string>("relatedLinks")))
                        {
    
                      var linkUrl = (bool)item.isInternal ? Library.NodeById(@item.link).Url : item.link;
                       var linkTarget = (bool)item.newWindow ? "_blank" : null;
                      <li><a href="@linkUrl" target="@linkTarget">@item.caption</a></li>
    
                      }
                 </ul>
    

    As detailed in Amirs post here

Please Sign in or register to post replies

Write your reply to:

Draft