by

The More You Know: Tridion 2011 and Keywords

The More You Know (Trademarks and Copyrights of NBC)
The More You Know (Trademarks and Copyrights of NBC)

I’m a child of the 80’s. Every Saturday morning, between Teenage Mutant Ninja Turtles, X-Men, and GI-Joe I’d catch at least two or three Public Service Announcements from NBC where they’d teach me about bullying or doing my homework, and end it with, “The More You Know.”

The last few Tridion 2011 projects I’ve had have used Categories and Keywords pretty extensively. The Keyword class is relatively simple, but quirky. After discovering another extremely odd quirk a few days ago when I was debugging something for a client, I had to explain the craziness of the issue in our next status call. After I explained the issue and a few folks’ mouths were agape and they were scratching their heads, it was one of those moments where you just have to quote NBC: “Yep. The more you know”.

In Tridion, Value is not a property of Keyword

So, consider what the content author sees as they create a keyword:

Key, Value, and Description Fields
Key, Value, and Description Fields

One thing that I learned a while back is that, while you see the word “value”, any attempts to access this property by writing Keyword.Value are in vain. The content of this field is actually written into the .Title property.

Right for Templates:

@Fields.SomeKeyword.Title

Wrong for Templates:

@Fields.SomeKeyword.Value

the more you know

In Tridion, if you localize a keyword, the Key won’t

So, that’s the one that just kind of had me scratching my head. This client had a multilingual site, and I absolutely could not figure out why a particular component was not showing the localized text I was expecting. It’s probably because This was a French / English site, the keyword was the name of a flavor, which itself was French:

French / English Keyword
An unlocalized keyword

I had simply picked the right wrong keyword to debug.  Had I looked at some other keyword, in its localized form, I would’ve noticed something was awry:

A Localized Keyword
You’ll notice that the “key” is still in English

Now, what’s nifty, is that this field isn’t greyed out when it’s localized. So it gives the illusion that it, too, can be edited. But, if you try to edit that key field, Tridion will stop you:

Error Message when you change the key of a localized keyword
Error Message when you change the key of a localized keyword

Right for templates:

Displaying the .Title:

@Fields.SomeKeyword.Title

Wrong for Templates:

Displaying the .Key

@Fields.SomeKeyword.Key

So, in a nutshell, I made one mistake in choosing to display the .Key, and then another by picking the worst possible keyword to debug.

The more you know

Summing up the Quirks with Keywords

That value field is actually the .Title property. Though counter-intuitive for us as developers, it makes sense that the folks at SDL did it that way, because they want the keyword to be a sort of “key-value” pair. And when you’re displaying information from that keyword, display either the .Title or the .Description, as those are the two fields which are localized. Since the .Title is also the name of this keyword as it would appear in Tridion, you may want to use .Description if you want one thing for the content authors and another for the end-users.