Search

The problem I have is the following: I have 6 pages, of which one should have one extra css file. I don’t want to include it in the rest because it overwrites properties.

For each page I have a very generic xslt template, with a master-like master template. Now, I would like to include the stylesheet to the single page, without making a new master.

In the past, I would have done this by using php. like so: $header->appendChild($css_link_element)

My question is, is there a similar way to do it using xslt?

Of course. Put your headers in a special template in master.xsl:

<xsl:template name="page-head">
    <link rel="stylesheet" type="text/css" href="{$workspace}/css/styles.css" />
</xsl:template>

Then, in your “page with special needs” add a template like this

<xsl:template name="page-head">
    <link rel="stylesheet" type="text/css" href="{$workspace}/css/styles.css" />
    <link rel="stylesheet" type="text/css" href="{$workspace}/css/special-styles.css" />
</xsl:template>

Since the templates in your pages have a higher priority than the ones in your master, it will be overwritten where necessary and otherwise fallback to default.

Yeah, that was what I already had indeed ;)

Right now, I have the page-head utility included in all other templates except the “page with special needs”. In the “p.w.s.n.” I declare the template with the other files added. (Exactly the same as your solution, only the first part is in a utility)

But now, If I wanted to add a new css file to all pages, I would have to edit the template in two places (and because I will definitely forget this, I like to avoid that!)

Can it be done by passing something with the template params?

Just to tell the master to include another stylesheet when calling it in the page template?

No need for another utility. You could also define an empty template “custom-head” and fill it only where necessary.

Just to tell the master to include another stylesheet when calling it in the page template?

I would regard this as bad templating style.

Thanks! Never thought of using an empty template, perfect!

I would regard this as bad templating style.

From a xslt or user point of view?

[Edit] Im am slowly getting there.. Is there a way to test if a template has already been declared?

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