我正在尝试使用 C# TBB 获取类别中存在的关键字,以使用以下 DWT TBB 中的输出。
为此,我有一个带有类别字段的组件。
我正在尝试编写以下 C# TBB 来获取关键字值。
<%@Import NameSpace="Tridion.ContentManager.Templating.Expression" %>
try
{
string className = package.GetValue("Component.Fields.title");
KeywordField keywordField = package.GetKeywordByTitle(className);
package.PushItem("Class", package.CreateStringItem(ContentType.Text, keywordField.Value.Key));
}
catch(TemplatingException ex)
{
log.Debug("Exception is " + ex.Message);
}
但我收到以下编译错误。
无法编译模板,因为:错误 CS0246:找不到类型或命名空间名称“KeywordField”(您是否缺少 using 指令或程序集引用?)错误 CS1061:“Tridion.ContentManager.Templated.Package”不包含找不到“GetKeywordByTitle”的定义,并且找不到接受“Tridion.ContentManager.Template.Package”类型的第一个参数的扩展方法“GetKeywordByTitle”(您是否缺少 using 指令或程序集引用?)
请建议我如何实现它?
提前致谢
Jeremy 建议您学习 API,我为您提供了从类别中获取关键字的示例。希望它可以帮助
包含文件
using Tridion.ContentManager;
using Tridion.ContentManager.CommunicationManagement;
using Tridion.ContentManager.Templating.Assembly;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.ContentManagement.Fields;
using Tridion.ContentManager.Templating;
示例代码,您可以根据您的要求在此处使用循环中的键和值。
string catID = package.GetByName("CategoryID").GetAsString();
TcmUri catURI = new TcmUri(int.Parse(catID), ItemType.Category, PubId);
var theCategory = m_Engine.GetObject(catURI) as Category;
catKeywords = GetCatKeywords(theCategory);
string strSelect = "<select>";
foreach (Keyword k in catKeywords)
{
k.Key // Keyowrd key
k.Value // KEyword Value
}
//keyword list
private IList<Keyword> GetCatKeywords(Category category)
{
IList<Keyword> keywords;
if (!Utilities.IsNull(category))
{
Filter filter = new Filter();
filter.BaseColumns = ListBaseColumns.IdAndTitle;
keywords = category.GetKeywords(filter);
if (!Utilities.IsNull(keywords))
{
return keywords;
}
}
return null;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)