Search

It's possible to specify custom page types: is there a way to make use of this? E. g. having some XML that puts out those values? Or some global variables? This feature could be very handy when creating multilingual site as it would become quite easy to distinguish between languages and react in the templates depending on this.

Any ideas?

I'm using them to manage a navigation menu to display a different menu depending on what access has been granted to the user. Of course, it's still waiting for a user access control extension.

<xsl:template match="navigation">
  <ul id="nav">
    <xsl:choose>
      <xsl:when test="$page-type = 'system'">
        <xsl:apply-templates select="page[not(types/type = 'hidden') and not(types/type = 'login')  and not(@handle = 'system')]" mode="front-end"/>
        <xsl:call-template name="symphony-navigation"/>
      </xsl:when>
      <xsl:when test="$is-logged-in">
        <xsl:apply-templates select="page[not(types/type = 'hidden') and not(types/type = 'login')]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="page[not(types/type = 'hidden') and not(types/type = 'admin')]"/>
      </xsl:otherwise>
    </xsl:choose>
  </ul>
</xsl:template>

<xsl:template match="page">
  <li>
    <a href="{$root}/{@handle}/">
      <xsl:if test="@handle = $current-page or 
        (@handle = $current-page and $page-type = $current-page) or 
        (@handle = $parent-path and $page-type = $parent-path)">
        <xsl:attribute name="class">active</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="name"/>
    </a>
  </li>
</xsl:template>

<xsl:template match="page" mode="front-end">
  <li class="front-end">
    <a href="{$root}/{@handle}/">
      <xsl:if test="@handle = $current-page">
        <xsl:attribute name="class">active</xsl:attribute>
      </xsl:if>
      <xsl:value-of select="name"/>
    </a>
  </li>
</xsl:template>

Using page types should work just as well to display different menus based on language.

Where did you get this variable from? $page-type does not show up in the debug menu. Strange - I'll have a look at it ...

Page types seem just to be available in navigation DS but that's not what I'm looking for. I just need to know the page types for the currently displayed page. Is there a way to get these values?

I'm sure I'm missing something, it's certainly easy ... I just don't understand it. Any help appreciated!

Sorry, I didn't explain that very well. I declared a $page-type parameter as a global variable for each page. Unfortunately, this does not make it available to data sources for filtering.

<xsl:param name="page-type" select="'projects'"/>

I suppose it could be generated dynamically, but it didn't seem worth the effort, since the page types do not change dynamically.

My pages have two page types:

  • admin to make the page accessible only to admin users
  • projects to make it easy to specify what section each page is associated with

If you wanted to arrive at the same value as I have hard-coded above, I might do something like this.

<xsl:param name="page-type" select="/data/navigation//page[@handle = $current-page]/types/type[text() != 'admin']"/>

However, this XPath expression will match any page that has the same name as the current page. If there are pages with the same name, this expression will have to be made more specific. Also, if you have more than one page type, as I do, you will need some way to be able to select the type that you are looking for. It appears that page types are given an XML document order which is the same as the CSV order. So you could probably select by position. So if I have specified my page types as

 admin, projects

I could make sure all pages are given this order and always choose the page type in the second position of the XML document order:

<xsl:param name="page-type" select="/data/navigation//page[@handle = $current-page]/types/type[2]"/>

I hope that helps.

Thank you, bauhouse. I was thinking of a similar solution.

I have a huge number of pages but I have no need for a navigation DS. So I'm not happy about having to add so many superfluous lines of XML to my pages just to get their type. Maybe I need to tailor a special DS for my needs.

How about add a type column? Use a tag list. Make another section with types and use that for the tag list.

Then just create a DS that filters for the type.

That doesn't work in my case as I do not need to sort entries by language. I'd like to switch the language of my master template without having to use a long test condition in my XSL (test="'$page1 = 'name1' or '$page2 = 'name2' or '$page3 = 'name3' or '$page4 = 'name4' or '$page5 = 'name5' or ... '") when it would be so easy to use the page type.

I think I'm going to write a custom Data Source that just displays the page types of the current page :)

No I meant. My suggestion doesn't require you any XSL. Re-read :P

Create a new section: Page Types and create your page types. Create a Pages section, and/or add item: tag list. Use Suggestion List and select the Page Types section that includes all the different types of pages you'll have. Then just create a new Data Source. Add a filter selecting the tag list, and select the right type of page.

How did Nils resolve this and does anyone think the solution offered by ibolmo would work as well or differently?

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