2

We are using DXA 2.2.3 and have the following mappings:

[ExcludeFromCodeCoverage]
[SemanticEntity(EntityName = "Link", Prefix = "l")]
public class Link : EntityModel
{
    [Include]
    [SemanticProperty("l:internalLink")]
    [SemanticProperty("l:externalLink")]
    public string Url { get; set; }

    ...
}

The Url property is resolved to:

/content-management/sdl-tridion/sdl-tridion-sites/

But I would like to add an Id of a Component which it is linked to as an url fragment/hash, so for example I would like to have an url

/content-management/sdl-tridion/sdl-tridion-sites/#93730

In addition, this fragment should appear in the resolved link only in case the linked Component is based or not based on a certain Schema. So I need to check the Schema Id and then consider adding an anchor to a link.

What is a proper way to handle such a case? Any solution on web app side?

1
2

If you map a Component Link field to a property of type string, the semantic mapping will use the resolved link URL which is injected in the DXA R2 Data Model by the DXA Model Service/Extension.

Unfortunately, this part of link resolving is not customizable. However, if you map a Component Link field to an Entity Model, you will have access to the underlying Component ID (it will be mapped to the Entity Model's Id property).

If you give that Entity Model a string property which is annotated with [SemanticProperty("_self")], you will also have access to the resolved link URL.

You can then construct the combined URL yourself (for example, by adding a property to your Entity Model which combines the two).

1
  • BTW: You can also map the Component Link to a property of type Link. That also provides both the resolved URL and the Component ID. Jan 12 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.