问题
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