Keyword Path in SDL Tridion

血红的双手。 提交于 2019-12-23 09:27:44

问题


Could someone please give some idea on how this can be done? This might be very simple and basics, but i couldn't figure this out.

Here is my requirement.

I have a category A with child keyword B and B got another Child Keyword C.

I want to get the exact path of selected keyword in my component template,Say for eg, if user selects keyword C, i need the value with path like A\B\C and not just as C. But Tridion always gives me the value as C and not as A\B\C . Component Schema is using "Tree" view to select the keywords.

Should I be writing dreamweaver custom functions to handle this? Or does tridion comes with some handler for this?

Any help would be highly appreciated. Thank you!

Thanks, KK


回答1:


As you just found out, the Tridion Keyword Hierarchy is "fake" - Keywords are stored as a flat list, not as a hierarchical list (like you would have with folders). The information about the parent and children keywords is stored in the keyword itself.

There are solutions for this - of course, for instance you can use this in a 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 "go up" the hierarchy. HOWEVER a keyword can have multiple parents, I'll leave that up to you to fix...




回答2:


Keywords within a 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 may not be a single path leading from the root to your Keyword.

If in your situation the category can be represented as a tree, you can of course build a single path to each keyword. In that case you'll need some (C#) code that walks up the parents axis and concatenates the names. You can put this code either:

  1. in a TBB that you put into your template before the DWT OR
  2. in a custom Dreamweaver function.

Either way will work fine.



来源:https://stackoverflow.com/questions/11191010/keyword-path-in-sdl-tridion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!