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.
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
Thanks Dibs
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
Thanks,
Alex
Cheers Alex
I will give the package a go, but is their way to do it without the package ?
Thanks Dibs
Hi Dibs,
Yes, you can do it without package, Related Links stores data in JSON.
Use this code:
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
fieldset.GetValue
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
Cheers Dibs
Glad that it works, have a nice day!
/Alex
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.