问题描述
这类似于这个 XSLT 问题,但最终是针对 DWT.
This is similar to this XSLT question, but ultimately for DWT.
我们可以通过 C#'sa 关键字获得 关键字待定.
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));
在 DWT 中,我有时需要组件中选定关键字的 key
.
In DWT, I sometimes want the key
of a selected keyword in a component.
从包中添加和获取这些是正确的方法吗?
@@Component.Metadata.State@@
获取我的价值.直接从 DWT 引用密钥会很棒,但我没有看到任何迹象表明 DWT 会公开它.
@@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.
推荐答案
作为 John 答案的另一种选择.如何采用与 Will 的获取组件模板 Uris"类似的方法并编写一个 TBB 来迭代类别的关键字并将它们写入具有所需输出值的包中?然后,您可以直接从 DWT 使用这些值,并进行双重评估",例如:
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@@
这篇关于我应该如何从 DWT 获取 Keyword Key的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!