Skip to content

Instantly share code, notes, and snippets.

@freewayspb
Created April 29, 2015 16:18
Show Gist options
  • Save freewayspb/afc402490ffdf2b7e5ab to your computer and use it in GitHub Desktop.
Save freewayspb/afc402490ffdf2b7e5ab to your computer and use it in GitHub Desktop.
multi-level dropdown bootstrap hostcms menu
<!-- Запишем в константу ID структуры, данные для которой будут выводиться пользователю -->
<xsl:variable name="current_structure_id" select="/site/current_structure_id"/>
<xsl:template match="structure">
<li>
<xsl:if test="$current_structure_id = @id or count(.//structure[@id=$current_structure_id]) = 1">
<xsl:attribute name="class">active</xsl:attribute>
</xsl:if>
<xsl:if test="count(structure[show=1])!=0">
<xsl:attribute name="class">dropdown</xsl:attribute>
</xsl:if>
<!-- Определяем адрес ссылки -->
<xsl:variable name="link">
<xsl:choose>
<!-- Если внешняя ссылка -->
<xsl:when test="url != ''">
<xsl:value-of disable-output-escaping="yes" select="url"/>
</xsl:when>
<!-- Иначе если внутренняя ссылка -->
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="link"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Ссылка на пункт меню -->
<a href="{$link}" title="{name}" hostcms:id="{@id}" hostcms:field="name" hostcms:entity="structure">
<xsl:if test="count(structure[show=1])!=0">
<xsl:attribute name="class">dropdown-toggle</xsl:attribute>
<xsl:attribute name="data-toggle">dropdown</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
<xsl:if test="count(structure[show=1])!=0">
<b class="caret"></b>
</xsl:if>
</a>
<xsl:if test="count(structure)!=0">
<xsl:apply-templates select="structure[show=1]" mode="dropdown"/>
</xsl:if>
</li>
</xsl:template>
<xsl:template match="structure" mode="dropdown">
<ul class="dropdown-menu">
<li>
<a href="{url}">
<xsl:value-of disable-output-escaping="yes" select="name"/>
</a>
</li>
</ul>
</xsl:template>undefined</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment