我想基於查詢將asp:dropdownlist綁定到一些sitecore項目。通過查詢,我想返回繼承模板「Site Root」的項目。繼承模板上的Sitecore SelectItems
當我使用:
Sitecore.Context.Database.SelectItems("/sitecore/content/*[@@templatename='Site Root']");
它僅返回「站點根目錄」,而不是繼承此模板的模板的模板項目。
如何獲取查詢以返回繼承此模板的項目?
我想基於查詢將asp:dropdownlist綁定到一些sitecore項目。通過查詢,我想返回繼承模板「Site Root」的項目。繼承模板上的Sitecore SelectItems
當我使用:
Sitecore.Context.Database.SelectItems("/sitecore/content/*[@@templatename='Site Root']");
它僅返回「站點根目錄」,而不是繼承此模板的模板的模板項目。
如何獲取查詢以返回繼承此模板的項目?
您不能在繼承模板
這裏查詢的返回繼承特定模板的所有模板的查詢。但要小心,因爲它表現不佳。
/sitecore/templates//*[contains(@__Base template, '<MY TEMPLATE ID>')]
如果性能問題,你可能會更好使用Sitecore的ContentSearch查詢模板。有一個__template計算字段需要首先激活。詳情請參閱Sitecore-7-Enable-Default-Computed-Index-Fields。
好的,只是改變我的查詢,包括所有從該模板繼承的模板。 – Bevan 2011-03-28 03:21:43
這當然是一個選項,但您添加到查詢中的檢查越多,它可能運行得越慢。您還應該考慮使用Sitecore API代碼進行更通用的查詢,然後使用LINQ按「TemplateName」過濾結果項 – 2011-03-28 13:34:03