How should I get Keyword Key from DWT

陌路散爱 提交于 2020-01-04 03:49:14

问题


This is similar to this XSLT question, but ultimately for DWT.

We can get a keyword's key via a C# TBB.

ItemFields fields = new ItemFields(component.Metadata, component.Schema);
KeywordField keywordField = fields["state"] as KeywordField;

String stateValue = package.EvaluateExpression("Component.Metadata.state");

package.PushItem("statekey", package.CreateStringItem(ContentType.Text, keywordField.Value.Key));

In DWT, I sometimes want the key of a selected keyword in a component.

Is adding and getting these from the package the correct approach?

@@Component.Metadata.State@@ gets me the value. Referencing the key directly from DWT would be great, but I haven't seen anything to suggest DWT exposes it.


回答1:


As another alternative to John's answer. How about taking a similar approach to Will's "Get Component Template Uris" and write a TBB that iterates over a category's keywords and writes them out into the package with the desired output value? You'd then be able to use these values directly from DWT with a "double-evaluation" like:

@@Keyword${Component.Metadata.state}Value@@



回答2:


I suspect for this you would need to go down the TBB route as you suggest, or even write your own DWT function to expose it.

You can find an example of creating DWT functions here: http://www.tridiondeveloper.com/get-and-set-variables-in-dwts



来源:https://stackoverflow.com/questions/12509454/how-should-i-get-keyword-key-from-dwt

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