Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I see DXA code reading description field of a keyword component if it is available and not its name, I tried to look into the schema mapping to its model.. couldn't reach to the place where does this actually happen..

can anyone help me find it.. is it something which is DXA default feature ?

share|improve this question
up vote 4 down vote accepted

Here's what I see with reference to the Java project, you can find a similar class for .Net

See KeywordFieldConverter Class in dxa-tridion-provider, you will find that while getting Keyword's values in getStringValues they are picking the Keyword's Description by default, and if it's empty only then the title/name.

private List<String> getStringValues(List<Keyword> keywordValues) {
    final List<String> stringValues = new ArrayList<>();
    for (Keyword keyword : keywordValues) {
        stringValues.add(getKeywordDisplayText(keyword));
    }
    return stringValues;

}

private String getKeywordDisplayText(Keyword keyword) {
    return Strings.isNullOrEmpty(keyword.getDescription()) ? keyword.getTitle() : keyword.getDescription();
}

I can relate to this blog More you know Tridion & Keywords to understand why it's recommended to use description and not key/title, it will surely save you trouble.

share|improve this answer
    
Thanks Ashutosh ! – Vikas Kumar Feb 15 at 10:08

This behaviour is 'hardcoded' in the Model Mapping logic. Check out this line in Sdl.Web.Tridion.Mapping.DefaultModelBuilder:

string displayText = String.IsNullOrEmpty(keyword.Description) ? keyword.Title : keyword.Description;

The reason for this is that it is considered good practice to use keyword descriptions for display text. Often in implementations, the keyword title has a numeric prefix, or other additional information to ensure the keyword title is unique. Additionally some implementations leave the keyword title untranslated and put the localized value in the description.

As you can see from the code, if there is no description, the title is used, so you always have this fallback. What are you using descriptions for if its not display text?

share|improve this answer
    
Cool... it solves my problem. ahh ! its a client requirement and i guess i need to convince them not to break the law of standard practices. Thanks Will. :) – Vikas Kumar Feb 15 at 10:10
    
The description is getting used to specify company name which has recently acquired the client. Earlier they were only using title so this was not encountered. – Vikas Kumar Feb 15 at 19:23
    
@VikasKumar sounds like they should use Keyword Metadata for that, as it is incorrect usage of a description (typical case of metadata I would say). – Bart Koopman Feb 17 at 9:20
    
Yes indeed.... Thanks Bart. – Vikas Kumar Mar 14 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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