Copied to clipboard

Flag this post as spam?

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


  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jul 09, 2013 @ 16:19
    Martin Griffiths
    0

    get directory based url in XSLT for altTemplate

    Does anyone know if it's possible to get the altTemplate name for a URL in an XSLT macro?

    I'm using directory URLs so the format is...

    http://domain.com/page/templateName

    as opposed to...

    http://domain.com/page?altTemplate=templateName

    The reason I ask is for SEO, I want to be able to provide a different <title> in the <head> from the main document.

    Martin.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 09, 2013 @ 16:51
    Jan Skovgaard
    0

    Hi Martin

    Since it's an alternative template then the context used in the XSLT is still the one for $currentPage, which will then just give you the properties from your "page" and not your "templateName" alternative template.

    I'm not sure if this works but perhaps it's possible to check the value returned by the @template attribute in the returned XML. It might display the template id of the alternative template...but again...I'm not sure but could be worth the try. Because if it's different then you can make some logic to handle the title and meta descriptions accordingly.

    Looking forward to hearing from you.

    /Jan

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jul 09, 2013 @ 16:57
    Chriztian Steinmeier
    1

    Hi Martin,

    Shouldn't be a big problem - you have access to the actual URL via the Server Variables, and you know all the possibilities of template names, so something like this should help you get going:

    <xsl:variable name="URL" select="umbraco.library:RequestServerVariables('SCRIPT_NAME')" />
    
    <xsl:if test="contains($URL, '/templateName')">
        <!-- do something -->
    </xsl:if>

    Please note that this is the simplest way - not good if you need to check more than a few aliases - it doesn't cater for the situation where your altTemplate is named "contact" and you visit the page "/contacts/contact" - but if you need these, it can of course be extended.  

    /Chriztian

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Jul 09, 2013 @ 17:00
    Jan Skovgaard
    0

    Do'h! Of course! I really should have thought of that - Too much vacation mode...:D

    /Jan

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jul 09, 2013 @ 18:02
    Martin Griffiths
    0

    Hi all

    Many thanks for the quick advice but on further consideration we've decided to dump the use of altTemplate altogether in sections where SEO is important.

    If we kept them I'd have to fudge the titles, level and meta data for pages that effectively dont actually exist. The problem we're having is in using altTemplate a huge section of our site in the Google index has duplicates and we're worried about how this is affecting ranking.

    So i'm gonna create a bunch of child doctypes for our content using altTemplates instead. It's autogenerated stuff like; related news, related publications etc. 

    Martin.

     

     

  • wolulcmit 357 posts 693 karma points
    Jul 12, 2013 @ 10:01
    wolulcmit
    1

    duplicates wont matter if you use canonical tags
    Using Chriztians code above you could output a canonical tag which states where the content which should get the SEO juice lives.

    <link rel="canonical" href="http://yoursite/the-real-page-is-actually-here" />

Please Sign in or register to post replies

Write your reply to:

Draft