Copied to clipboard

Flag this post as spam?

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


  • Daniel 20 posts 40 karma points
    Jan 30, 2012 @ 20:49
    Daniel
    0

    Changing content by hostname language selection

    I'm trying to create several sites using one umbraco installation by setting up different domains with language keys. Trouble is though, there's a related links property that needs to change by the language used - which already draws it data from outside the hostname.

    I'm thinking the easiest thing, is to manually add the ID to which the related links option draws it data.

    Site Structure:

    Language (the one that has the related links property)
    - Front page (to which the hostname is attached)
    - Sub pages (which are at the same level and below the front page)

    And the xslt to the related links property:

    <?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"/>
         
      <!-- selectMenu, is the alias of the Related Links property -->
      <xsl:variable name="propertyAlias" select="string('selectMenu')"/>

      <xsl:template match="/">

          <ul id="selectedMenu">
            <xsl:for-each select="umbraco.library:GetXmlNodeById(1056)/* [name() = $propertyAlias and not(@isDoc)]/links/link">
              <li>
                <xsl:choose>
                  <xsl:when test="position() = last()">
                    <xsl:attribute name="class">last</xsl:attribute>
                  </xsl:when>
                </xsl:choose>
        
                <xsl:element name="a">
                  <xsl:if test="./@newwindow = '1'">
                    <xsl:attribute name="target">_blank</xsl:attribute>
                  </xsl:if>
                  <xsl:choose>
                    <xsl:when test="./@type = 'external'">
                      <xsl:attribute name="href">
                        <xsl:value-of select="./@link"/>
                      </xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="href">
                        <xsl:value-of select="umbraco.library:NiceUrl(./@link)"/>
                      </xsl:attribute>
                    </xsl:otherwise>
                  </xsl:choose>
                  <xsl:value-of select="./@title"/>
                </xsl:element>
              </li>
            </xsl:for-each>
          </ul>
          
    </xsl:template>

    </xsl:stylesheet>

    So, could anyone assist in modifying this xslt to change by the choice of language keys?

  • Yarik Goldvarg 35 posts 84 karma points
    Jan 30, 2012 @ 21:06
    Yarik Goldvarg
    0

     

    You can add property (macro container) to document type and use macro parameter to pass ID to xslt.

    Yarik

     

  • Daniel 20 posts 40 karma points
    Jan 31, 2012 @ 12:07
    Daniel
    0

    Could you provide an example please?

  • Yarik Goldvarg 35 posts 84 karma points
    Jan 31, 2012 @ 14:53
    Yarik Goldvarg
    0

    1. Add to your macro a new parameter of content tree.

    2. Go to Developer->Data Types->Macro Container (or create a new datafield of macro data container type) and add your macro.

     

    3. Go to:Settings->Document types->You document type->Generic properties->Add new property.

    and add a new property(type : "Macro Container")

    4. Modify yor template by adding an umbraco page field to the  template.

    5. Modify your xslt to 

    <?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:param name="contentNode" select="/macro/contentNode"/>      
      <!-- selectMenu, is the alias of the Related Links property -->
      <xsl:variable name="propertyAlias" select="string('selectMenu')"/>

      <xsl:template match="/">

          <ul id="selectedMenu">
            <xsl:for-each select="umbraco.library:GetXmlNodeById($contentNode)/* [name() = $propertyAlias and not(@isDoc)]/links/link">
              <li>
                <xsl:choose>
                  <xsl:when test="position() = last()">
                    <xsl:attribute name="class">last</xsl:attribute>
                  </xsl:when>
                </xsl:choose>
        
                <xsl:element name="a">
                  <xsl:if test="./@newwindow = '1'">
                    <xsl:attribute name="target">_blank</xsl:attribute>
                  </xsl:if>
                  <xsl:choose>
                    <xsl:when test="./@type = 'external'">
                      <xsl:attribute name="href">
                        <xsl:value-of select="./@link"/>
                      </xsl:attribute>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:attribute name="href">
                        <xsl:value-of select="umbraco.library:NiceUrl(./@link)"/>
                      </xsl:attribute>
                    </xsl:otherwise>
                  </xsl:choose>
                  <xsl:value-of select="./@title"/>
                </xsl:element>
              </li>
            </xsl:for-each>
          </ul>
          
    </xsl:template>

    </xsl:stylesheet>

     

     

     

    Hope will help.

    yarik

  • Daniel 20 posts 40 karma points
    Jan 31, 2012 @ 16:11
    Daniel
    0

    Sounds almost too complicated to bother with, no offence. I appreciate the work in your reply Yarik, but I don't understand the idea and purpose of it, nor why it isn't possible to do something like this instead:

    if language = da-DK then do this >
    ( complicated xslt pasted above )

    else if language = en-US then do this >
    ( same complicated xslt pasted above )

    And so on.. at this point you can probably tell that I'm more of a front-end programmer..

    Considering the fact that each root element of each site has a domain and language setup in it, this aught to be possible, right?

  • Matt Bliss 176 posts 234 karma points c-trib
    Jan 31, 2012 @ 18:41
    Matt Bliss
    0

    Hi Daniel,

    A few questions

    1) Is you site structure...

    Language (the one that has the related links property)
    Front page (to which the hostname is attached)
    Sub pages (which are at the same level and below the front page)

    ...repeated once for each site in the installation?

    2) In you xslt you have a hard coded node id (1056). What does that relate to?

    3) Which if these levels is the xslt attached to?

    Matt

     

  • Daniel 20 posts 40 karma points
    Jan 31, 2012 @ 19:27
    Daniel
    0

    Matt, you're absolutely awesome for sticking with this so here's the answers:

    The site structure is as such:


    The hardcoded ID is related to the language page [DK], and it'd have to change once per language so there'd have to be a different ID for the [EN] site. In the future there will be a norwegian, swedish and possibly a german language as well, so ID references for those sites will be have to be added too.

    I hope that answers your questions sufficiently. :)

  • Matt Bliss 176 posts 234 karma points c-trib
    Jan 31, 2012 @ 19:44
    Matt Bliss
    0

    Hi Daniel,

    If I've understood correctly then in either the 'Forside' or 'Frontpage' nodes (lets give them alias of 'HomePage') you would like to use xslt to pick up the 'DK' or 'EN' nodes (let give them an alias of 'Language') and get a propert value from them for related nodes (Alias 'links' fro example)

    In which case in you xslt file you could create an xslt variable for the 'Language' node:

    <xsl:variable name="langNode" select="$currentPage/ancestor-or-self::Language [@isDoc][1]"/>

    And then access the values from that node as follows:

    <xsl:value-of select="$langNode/links"/>

    You could actually get the level imediately above with a more simple xpath selector, but the above example would also work in your 'Sale' / 'Salg' sub folders so is more flexible.

    I hope this helps

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft