Search

Hey there. I’ve been trying to make a dropdown menu for my site. There’s two sections - headmenu and dropdown. headmenu is the main section and dropdown is subsections to dropdown.

I’ve been to trying to make something like this

<ul id="headmenu">
<li> entry
    <ul class="dropdown" id="someid">
      <li>entry
          <ul class="dropdown">
             <li>entry</li>
             <li>entry</li>
          </ul>
      </li>
    </ul>
</li>
</ul>

The headmenu XML example:

<entry id="99" headmenu="0" dropdownmenu="6">
   <link handle="services">services/</link>
   <title handle="pakalpojumi">Pakalpojumi</title>
</entry>

And dropdownmenu example:

<entry id="102">
   <parent>
      <item id="99" handle="pakalpojumi" section-handle="headmenu" section-name="headmenu">Pakalpojumi</item>
   </parent>
   <link handle="service-kanalizacijas-sistemas">service/kanalizacijas-sistemas/</link>
    <title handle="kanalizacijas-sistemas">Kanaliz?cijas sist?mas</title>
</entry>

The only thing is - I can’t think how to write the XSLT code to make it right. Could somebody help, please? Sorry for my bad English, hope you could understand me :D Thank you already.

Why not just use symphony’s default navigation datasource with the Recursive Navigation utility?

I’d try the following:

<ul id="headmenu">
    <xsl:apply-templates select="entry[not(parent/item)]" mode="parent" />
</ul>

<xsl:template match="entry" mode="parent">
    <li><xsl:value-of select="title" />
        <ul class="dropdown" id="menu-{link/handle}">
            <xsl:apply-templates select="../entry[parent/item/@id = current()/@id]" mode="child" />
        </ul>
    </li>   
</xsl:template>

<xsl:template match="entry" mode="child">
    <li><xsl:value-of select="title" /></li>
</xsl:template>

The magic happens in lines 2 (select all entries that do not have a parent) and 8 (select all entries that have a parent with the id equal to the current node).

miathrom: I do not like the quality of the Recursive Navigation templates.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details