Search

Hi,

I've got a fairly complex problem. At least to explain. Any advice is welcome!

I have a template in Pages/Home.xsl that calls Utilities/Master-template.xsl. This master template then applies other templates, based on the current page-type. I want to set a variable in the template for the page-type, like a header-title-tag or other meta-information, and use that variable in the top of the master-template. How can I get the information there?

Example of the master-template.xsl:

<xsl:import href="menu.xsl" />
<xsl:import href="footer.xsl" />
<xsl:import href="login.xsl"/>
<xsl:import href="user-not-enough-rights.xsl"/>
<xsl:import href="user-not-active.xsl"/>
<xsl:import href="user-check-rights.xsl"/>

<xsl:output method="html" omit-xml-declaration="yes" indent="no" />

<xsl:template match="/">
<html>
<head>
<title>???</title>
</head>
<body>
<xsl:call-template name="menu"/>
<div class="main-content grey-bg">
<xsl:apply-templates/>
</div>
<xsl:call-template name="footer"/>
<xsl:call-template name="bottom-scripts"/>
</body>
</html>

Thanks!

please have a lock at: https://github.com/germchaos/workspace/blob/master/utilities/html-head-metas.xsl

and have in mind: a varibale once defined oin xsl could not be overwritten. so is does noit matter whether you define some variables in your page tempalte or not as loang as you define deafults in your (modified?) xslt-util.

This has been answered before.

Use the mode feature.

In your master template you can use

<head>
    ~head stuff~
    <xsl:apply-templates mode="head"/>
</head>
<body>
    <xsl:apply-templates/>
</body>

At the bottom of your master, add this

<xsl:template match="data" mode="head">
    ~default stuff or leave empty~
</xsl:template>

in case your page does not have specific head content. Otherwise your XSLT will break.

Now on any page, you can add

<xsl:template match="data" mode="head">
    ~stuff to go in your head~
</xsl:template>
<xsl:template match="data">
    ~regular body stuff~
</xsl:template>

mode can be anything, so you can have one for your footer, sidebar, etc.

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