Key path in SDL Tridion

Can someone please give some idea how this can be done? It can be very simple and thorough, but I could not understand it.

Here is my requirement.

I have category A with a child keyword B and B gets another keyword for children C.

I want to get the exact path for the selected keyword in my component template. Say, for example, if the user selects the C keyword, I need a value with a path like A \ B \ C, and not just like C. But Tridion always gives me a value like C, and not like A \ B \ C. The component diagram uses the Tree view to select keywords.

Do I have to write custom Dreamweaver functions to handle this? Or does tridion come with some handler for this?

Any help would be greatly appreciated. Thanks!

Thanks, KK

+6
source share
2 answers

As you just learned, the Tridion keyword hierarchy is "fake." Keywords are stored as a flat list, and not as a hierarchical list (for example, you have folders). The parent and children keyword information is stored in the keyword itself.

There are solutions for this - of course, for example, you can use this in C # TBB:

Keyword keyword = new Keyword(new TcmUri("tcm:28-3368-1024"), session); string hierarchy = keyword.Title; bool done = false; while(!done) { if (keyword.ParentKeywords.Count > 0) { foreach (Keyword k in keyword.ParentKeywords) { hierarchy = k.Title + " > " + hierarchy; } keyword = keyword.ParentKeywords[0]; } else done = true; } // Include Category hierarchy = keyword.OrganizationalItem.Title + " > " + hierarchy; 

EDIT: Updated to recursively "raise" the hierarchy. HOWEVER, several parents can have a keyword, I will leave it to you to fix it ...

+8
source

The keywords in the category are unique, so Tridion can safely refer to them by their name (and / or their TCM URI, of course). And since a keyword can have multiple parents, there can be no path leading from the root to your keyword.

If in your situation a category can be represented as a tree, you can, of course, create one path to each keyword. In this case, you will need a code (C #) that approaches the axis of the parents and combines the names. You can also put this code:

  • in the TBB that you put in your template before DWT OR
  • in the custom Dreamweaver function.

In any case, this will work fine.

+5
source

Source: https://habr.com/ru/post/918948/


All Articles