Reputation: 2269
As I'm concerned with performance issues relating to IsItemOfType() function (read more here), I'm trying to rewrite it using GetItemsOfType() function.
Here is a code:
<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>
Unfortunately GetItemsOfType() function is not returning item with children? Any idea why?
Upvotes: 2
Views: 274
Reputation: 2712
It seems that the GetItemsOfType() only looks on templates inherited from the current template of the item. So if item1 is of template t1, and t1 inherits from t2, it will only return the item1, if you ask if it inherits from t2 and not t1.
You could just code it your self. It is not that hard. You can do something like this:
public bool InheritsFrom(Item item, ID templateIdToTest)
{
Template template = TemplateManager.GetTemplate(item);
if (template.ID == templateIdToTest)
return true;
return template.DescendsFrom(templateIdToTest);
}
Upvotes: 3