Search

Hello, dear community.

Only recently I have discovered Symphony and also XSLT, but I've instantly grown a big fan. However, I've got a problem I can't seem to solve now. I do have a navigation.xsl as a utility, which is included in all pages that need it. Because these are obviously more than 1, I need to do a conditional test to mark the currently selected page as active. To do that, I'd to add a class="active" attribute to the li-element, but I am struggling because I don't know how to do inline conditional statements. This is what I have tried so far. Can anyone give me a hint on how to compare a Symphony parameter to a string?

There's a special <xsl:attribute name="something"> element to add attributes to your markup. Those can be nested within other flow-control elements:

<li>
  <xsl:if test="$current-page = 'home'">
    <xsl:attribute name="class">active</xsl:attribute>
  </xsl:if>
  <a href="{$root}">HOME</a>
</li>

But you should take a look at the navigation.xsl file that comes with the default install. Right now it seems you're doing your entire navigation statically while it could be created automatically from the actual pages you've created on the backend.

Thanks, this works like a charm. :) Also, thanks for the tip. Yes, indeed, most of my navigation is done static. Mostly because I don't know much better at this moment, but also because I only have 4 pages in the navigations (2 with dropdowns, where the dropdown contents will be dynamic). For now, I will try to get it working like this. When I've finished the page I might have a bit more XSLT experience and am able to upgrade the navigation. ^^

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