Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Soeren Sprogoe 575 posts 259 karma points
    Dec 08, 2009 @ 11:02
    Soeren Sprogoe
    0

    Setting TITLE and META DESCRIPTION from macro

    Hi everyone,

    is is possible to set the page title and meta description from an XSLT macro further down the page?

    I know I've seen the trick somewhere, just can't seem to find it again.

    Best regards,
    Soeren Sprogoe

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 08, 2009 @ 11:35
    Lee Kelleher
    0

    Hi Soeren,

    If you've got <head runat="server"> then you should be able to use an XSLT extension to set the <title> and find the meta description control/tag (easier to locate if you give it an ID and runat=server).

    Otherwise you could try putting a macro in the <head> and generate/populate the title/meta-description from there, (which you'd probably already thought of).

    Cheers, Lee.

  • Soeren Sprogoe 575 posts 259 karma points
    Dec 09, 2009 @ 13:11
    Soeren Sprogoe
    0

    Hi Lee,

    thanks for your reply.

    I can't set the title in a macro in the header, as the content is decided by something going on further down the page. Usually you have the TITLE in your master page, and I want to change it to something else more or less dependant on the actual doc type. Fx. @nodeName is okay for all regular pages, but on all product pages I want the TITLE to be "Buy a @nodeName for only xxx DKK".

    So I guess I should try and write and XSLT extension for this, if one doesn't exist already.

    Best regards,
    Soeren Sprogoe

  • Laurence Gillian 600 posts 1219 karma points
    Dec 09, 2009 @ 13:36
    Laurence Gillian
    0

    You should be able to write this as a XSLT Macro,

    This could use xsl:choose, when parent id=shop section, then get the the title and also the price.

    Should be really simple and no need for a custom extension.

    /L

  • David Tak 7 posts 27 karma points
    Jun 16, 2012 @ 16:54
    David Tak
    0

    hi

    i'm pretty new at everything and i'm doing ok but something i just can't get to work
    i'm trying to set up a xslt file so my page title changes, but it wont grab the info out of my doc

    this is my xslt file, somhow the information i put in at the tab sitename in my content manager doesn't appear in the page title:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp "&#x00A0;">
    ]>
    <xsl:stylesheet
            version="1.0"
            xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
            xmlns:msxml="urn:schemas-microsoft-com:xslt"
            xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
            exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">

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

      <xsl:param name="currentPage"/>

      <xsl:variable name="homepageNode" select="$currentPage/ancestor::root/HomePage"/>

      <xsl:template match="/">
        <title>
          <xsl:choose>
            <xsl:when test="string-length($currentPage/data[@alias='seoTitle']) &gt; 0">
              <xsl:value-of select="$currentPage/data[@alias='seoTitle']"/>
            </xsl:when>
            <xsl:when test="$homepageNode/@id = $currentPage/@id">
              <xsl:value-of select="$homepageNode/data[@alias='siteName']"/> - <xsl:value-of select="$homepageNode/data[@alias='siteDescription']"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:value-of select="$currentPage/data[@alias='siteName']"/> | <xsl:value-of select="$currentPage/@nodeName"/>
            </xsl:otherwise>
          </xsl:choose>
        </title>
      </xsl:template>

    </xsl:stylesheet>

     

    Please help :D

  • Dan Okkels Brendstrup 101 posts 197 karma points
    Jun 17, 2012 @ 15:30
    Dan Okkels Brendstrup
    2

    @David: You're calling the siteName alias on both $homepageNode and on $currentPage, and in the latter case, it'll only work when you are actually on the homepage (which is then the $currentPage).

    It looks like your example is a mix of pre-4.5 and post-4.5 XML schema, but on the new schema, I'd to this:

    <xsl:template match="/">
    <title>
    <xsl:apply-templates select="$currentPage" mode="title"/>
    </title>
    </xsl:template>

    <!--If a node has content for the seoTitle property, output that-->
    <xsl:template match="*[normalize-space(seoTitle)]" mode="title" priority="1">
    <xsl:value-of select="seoTitle"/>
    </xsl:template>

    <!--If we're on the homepage, output the sitename and the site description-->
    <xsl:template match="HomePage" mode="title">
    <xsl:value-of select="concat(siteName, ' - ', siteDescription)"/>
    </xsl:template>

    <!--For all other pages, output the sitename and the name of the current page-->
    <xsl:template match="*" mode="title">
    <xsl:value-of select="concat(ancestor-or-self::HomePage/siteName, ' - ', @nodeName)"/>
    </xsl:template>
  • David Tak 7 posts 27 karma points
    Jun 18, 2012 @ 19:55
    David Tak
    0

    @dan

    thanks a million, this works like a charm.
    now i can finally go on with the rest.

    Thanks again

Please Sign in or register to post replies

Write your reply to:

Draft