Search

Let’s say that I have 3 page templates: t1.xsl, t2.xsl and t3.xsl.

I would like to use t1.xsl if there are no arguments:

http://domain.com/parent/

t2.xsl if there is one:

http://domain.com/parent/something

t3.xsl if there are two:

http://domain.com/parent/something/something

The parent page should be the same in all cases: /parent.

It is possible: I could make a page template which checks the number of arguments and then calls the right template.

Is there any more friendly way to do this?

I don’t know of anything more simple than doing essentially what you suggest:

<xsl:choose>
    <xsl:when test="$url-param2 != ''">
        <xsl:call-template name="t3"/>
    </xsl:when>
    <xsl:when test="$url-param1 != ''">
        <xsl:call-template name="t2"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:call-template name="t1"/>
    </xsl:otherwise>
</xsl:choose>

I have not tested this but I think it should work.

XSLT templates used in any page request transformation are associated with a symphony Page. You can’t determine what xslt to include based on the request state beyond the Page being requested.

Assuming you are using a single symphony page with 2 url parameters, this means you will need some ‘controller’ xslt to determine what templates to apply. In this scenario, t1, t2, and t3 will all be loaded into the transformation and ‘in play’.

I would suggest attaching modes to these three templates. Then create an initial controller template (perhaps matching on ‘/’ ) that checks for the content of the url-parameters, and based on this, appliess templates within one of the three modes.

This approach also assumes that your output needs are completely exclusive based on the depth of the url; often this isn’t the case, and there will be some xslt that is common among them all.

edit: wiseolman’s approach will work also; using modes just keeps things more declarative. The best approach depends on your specific needs & preference.

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