Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
GetItemSoftType()sitecore扩展函数返回什么?_Sitecore_Xslt 1.0 - Fatal编程技术网

GetItemSoftType()sitecore扩展函数返回什么?

GetItemSoftType()sitecore扩展函数返回什么?,sitecore,xslt-1.0,Sitecore,Xslt 1.0,由于我关心的是与IsItemOfType()函数()相关的性能问题,所以我尝试使用GetItemSoftType()函数重写它 下面是一个代码: <xsl:variable name="home" select="ancestor-or-self::item[sc:IsItemOfType('_MenuRoot',.)]"></xsl:variable> <xsl:variable name="home2" select="sc:GetItemsOfType('_M

由于我关心的是与IsItemOfType()函数()相关的性能问题,所以我尝试使用GetItemSoftType()函数重写它

下面是一个代码:

<xsl:variable name="home" select="ancestor-or-self::item[sc:IsItemOfType('_MenuRoot',.)]"></xsl:variable>
<xsl:variable name="home2" select="sc:GetItemsOfType('_MenuRoot', ./ancestor-or-self::item)"></xsl:variable>        
<div>
   <xsl:value-of select="count($home/item)" /> <!-- returns 4 -->
   <br />
      <xsl:value-of select="count($home2/item)" /> <!-- returns 0 ??? --> 
   <br />
</div>



很遗憾,getItemSoftType()函数没有返回包含子项的项?
知道原因吗?

GetItemSoftType()似乎只查看从项目的当前模板继承的模板。因此,如果item1是模板t1,并且t1继承自t2,那么如果您询问它是否继承自t2而不是t1,它将只返回item1

你可以自己编写代码。这并不难。您可以这样做:

    public bool InheritsFrom(Item item, ID templateIdToTest)
    {
      Template template = TemplateManager.GetTemplate(item);

      if (template.ID == templateIdToTest)
        return true;

      return template.DescendsFrom(templateIdToTest);
    }

你的菜单根改变了吗?如果它是常量,我会硬编码。@marto,谢谢你的回复,但我不喜欢建议的方法,因为我正在创建依赖项并失去可重用性(如果我正确理解你的建议(按键/id/name引用菜单根项))