Search

Sorry for being a noob at this but is there a way to get the entry title into the title tag when you're on that entry's page?

If you are using the default Symphony theme, edit a utility called get-article.xsl.

Find the following code

<h3>
  <a href="{$root}/articles/{title/@handle}/"><xsl:value-of select="title"/></a>
</h3>

and change it to

<h3>
  <a href="{$root}/articles/{title/@handle}/" title="{title}"><xsl:value-of select="title"/></a>
</h3>

The curly brackets allow you to add the value of a parameter or XML node to the HTML.

I think huyaroo means the <title> tag in the html head...

Right. Edit the utility called page-title.xsl and change it to the following:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="page-title">
  <xsl:value-of select="$website-name"/>
  <xsl:text> &#8212; </xsl:text>
  <xsl:value-of select="$page-title"/>
  <xsl:if test="$current-page = 'articles'">
    <xsl:if test="$entry">
      <xsl:text> &#8212; </xsl:text>
      <xsl:value-of select="/data/articles/entry/title"/>
    </xsl:if>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>

I had to add the test for $current-page so that the other pages wouldn't break, since the other pages do not have $entry as a URL parameter, and you would get an undeclared variable error.

Awesome bauhouse! I have much to learn about XSL and Symphony. I've been trying this for days to get the <title> tag to work.

Glad that worked. There is a bit of a learning curve, but it's definitely worth it.

This produces a header that looks like this: Sitename - Articles - Article Title, which can get a bit unwieldly.

If you'd just like the article title in the head, use this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template name="page-title">

    <xsl:value-of select="/data/articles/entry/title"/>

</xsl:template>

</xsl:stylesheet>

So I am looking at titles as well, and will be looking at this from an SEO perspective after S2’s release but in the meantime I too have done similarly to bauhouse above. I had an extra requirement, as this is for a site with a page structure similar to this.

Overloading is the answer for me here, as the $entry parameter might or might not exist and xsl presumes you always know what exists. I know ahead of time that each area is laid out consistently as /data/section/entry/title and as well, I know that I am not needing to recurse farther down the parameters list... (maybe in the future I will, but at that point an SEO extension will do some work to solve this problem...)

Here is how I have changed it:

Update: As MrBlank Points out below, for relevance in SEO, order does count, so the template here is updated now to reflect that logic:

<xsl:param name="entry"/> 

<xsl:template name="page-title">
  <xsl:if test="$current-page != ''">
    <xsl:if test="$entry">
      <xsl:value-of select="///entry/title"/>
      <xsl:text> | </xsl:text>
    </xsl:if>
  </xsl:if>
  <xsl:value-of select="$page-title"/>
  <xsl:text> | </xsl:text>
  <xsl:value-of select="$website-name"/>

</xsl:template>

This will give me a consistent Section | Site or Entry | Section | Site <title> value for my site.

HTH :)

Not to muddy the water even more, but ...

For SEO friendly titles, wouldn't you want it to go like this instead?

Entry title | Section | Site Name

Essentially work from the most specific part first then to the least specific. That way, when Google or some other search engine returns results and truncates the titles, you get the important part first and not cut off.

Here's the page-title.xsl for my site with a when statement for each section.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="page-title" match="/">

  <xsl:choose>
    <xsl:when test="$current-page = 'home'">
        <xsl:text>Home // </xsl:text>
        <xsl:value-of select="$website-name"/>
    </xsl:when>
    <xsl:when test="$current-page = 'entry'">
      <xsl:value-of select="data/articles/entry/title"/>
        <xsl:text> // </xsl:text>
        <xsl:value-of select="$page-title"/>
        <xsl:text> // </xsl:text>
        <xsl:value-of select="$website-name"/>
    </xsl:when>
    <xsl:otherwise>
        <xsl:value-of select="$page-title"/>
        <xsl:text> // </xsl:text>
        <xsl:value-of select="$website-name"/>
    </xsl:otherwise>
  </xsl:choose>

</xsl:template>

</xsl:stylesheet>

Update: After posting this, I just noticed that I could make the // dividers into a variable so I can change them later. I think I'll do that. :-)

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