Copied to clipboard

Flag this post as spam?

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


  • Dibs 202 posts 991 karma points
    Mar 14, 2017 @ 23:21
    Dibs
    0

    Render related links within Archetype Data type

    Dear Umbraco Team

    I have created a Archetype Data Type with a related links property editor. How can i render the link ? i.e

    <a href="value of related link within Archetype DataType">click here</a>
    

    Thanks Dibs

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 15, 2017 @ 00:28
    Alex Skrypnyk
    0

    Hi Dibs

    It's really nice way to get RelatedLinks data from Archetype property if you install "Umbraco Core Property Value Converters" also - https://our.umbraco.org/projects/developer-tools/umbraco-core-property-value-converters

    With this package you will be able to get data with this code: Umbraco Core Property Value Converters

    @foreach (var fieldset in Model.GetPropertyValue<ArchetypeModel>("archetypeField"))
      {
        fieldset.GetValue<RelatedLinks>("relatedcontentlinks");
      }
    

    Thanks,

    Alex

  • Dibs 202 posts 991 karma points
    Mar 15, 2017 @ 08:48
    Dibs
    0

    Cheers Alex

    I will give the package a go, but is their way to do it without the package ?

    Thanks Dibs

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 15, 2017 @ 09:10
    Alex Skrypnyk
    100

    Hi Dibs,

    Yes, you can do it without package, Related Links stores data in JSON.

    Use this code:

    @using Newtonsoft.Json.Linq
    @foreach (var fieldset in Model.GetPropertyValue<ArchetypeModel>("YOURarchetypeField"))
    {
        foreach (var item in fieldset.GetValue<JArray>("YOURrelatedcontentlinksField"))
        {
            var linkUrl = (item.Value<bool>("isInternal")) ? Umbraco.NiceUrl(item.Value<int>("internal")) : item.Value<string>("link");
            var linkTarget = item.Value<bool>("newWindow") ? "_blank" : null;
            <a href="@linkUrl" target="@linkTarget">@(item.Value<string>("caption"))</a>
        }
    }
    

    As you see "Umbraco Core Property Value Converters" gives you much readable code, but of course it's one more package and maybe no sense if you use only one class. Hope it will solve your issue.

    Thanks,

    Alex

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 15, 2017 @ 10:11
    Alex Skrypnyk
    0

    fieldset.GetValue

  • Dibs 202 posts 991 karma points
    Mar 15, 2017 @ 10:15
    Dibs
    0

    Cheers Alex

    I did see that code on the our umbraco documentation but wasn't sure how to use it.

    I typed it in and hoped for the best : )

    It works

    Thanks Dibs

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Mar 15, 2017 @ 10:17
    Alex Skrypnyk
    0

    Cheers Dibs

    Glad that it works, have a nice day!

    /Alex

Please Sign in or register to post replies

Write your reply to:

Draft