Copied to clipboard

Flag this post as spam?

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


  • Bex 444 posts 555 karma points
    Jul 23, 2010 @ 17:14
    Bex
    0

    Get Url with the sub domain, rather than long structured path.

    Hi!

     

    I have a site that is laid out as follows:

     

    MainPage
    -----Areas
    -------Area1
    -----------Site1
    --------------Pages...
    -----------Site2
    --------------Pages...
    -------Area2
    -----------Site1
    --------------Pages...
    -----------Site2
    --------------Pages...

    All the "Site" Nodes (ie, site1. site2) have their own domains
    ie Site1.MainDomain.Com
    If I type in my browser Site1.Main.Domain.Com/Contentpagename.aspx it all works , But I can't seem to get get my xslt to generate this url, instead it generates Domain/Areas/Area1/Site1/Contentpagename.aspx.

    How do I get my xslt to generate the first example?

    Thanks

    Becky

     

  • Josh Townson 67 posts 162 karma points
    Jul 23, 2010 @ 17:19
    Josh Townson
    0

    I'm going to have to guess here, but you probably want NiceUrlFullPath rather than NiceUrl

    http://our.umbraco.org/wiki/reference/umbracolibrary/niceurlfullpath

    If that's not the case, can you post your XSLT that is causing the problem

    /Josh

  • Bex 444 posts 555 karma points
    Jul 26, 2010 @ 09:49
    Bex
    0

    Hi Josh

    I have just tried this and instead of giving "Domain/Areas/Area1/Site1/Contentpagename.aspx" It gives "Domain/MAINSITE/Areas/Area1/Site1/Contentpagename.aspx"

    Which does not work at all. Either way still not Domain/Contentpagename.aspx as I want.

    My XSLT is as follows:

    <?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"/>
    <!-- Input the documenttype you want here -->
    <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
    <!-- Use div elements around this macro combined with css -->
    <!-- for styling the navigation -->
    <xsl:variable name="level" select="4"/>
    <xsl:template match="/">
    <!-- The fun starts here -->
    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">
     
      -- <a href="{umbraco.library:NiceUrl(@id)}">
       <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
        <!-- we're under the item - you can do your own styling here -->
        <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
       </xsl:if>
       <xsl:value-of select="@nodeName"/>
      </a> --
     
    </xsl:for-each>
    </xsl:template>
    </xsl:stylesheet>

     

    Any ideas?

    Becky

  • Josh Townson 67 posts 162 karma points
    Jul 26, 2010 @ 10:31
    Josh Townson
    0

    Well - as far as I can tell that should have worked - best solution I can offer is to have a custom bit of C# do it. If you don't want to make an xslt extension, then you can do it like this:

    <?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:script="http://tempuri.org/"
    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="script 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"/>

    <!-- Input the documenttype you want here -->
    <!-- Typically '1' for topnavigtaion and '2' for 2nd level -->
    <!-- Use div elements around this macro combined with css -->
    <!-- for styling the navigation -->
    <xsl:variable name="level" select="4"/>

    <msxml:script implements-prefix="script" language="C#">
    <msxml:assembly name="System.Web"/>
    <msxml:using namespace="System.Web"/>
    <![CDATA[
    public string NiceUrlDomain(int nodeID)
    {
    try {
    string domain = System.Web.HttpContext.Current.Request.Url.Host.ToString()
    return domain + umbraco.library.NiceUrl(nodeID);
    } catch {
    return "";
    }
    }
    ]]>
    </msxml:script>


    <xsl:template match="/">

    <xsl:for-each select="$currentPage/ancestor-or-self::node [@level=$level]/node [string(data [@alias='umbracoNaviHide']) != '1']">

    -- <a href="{script:NiceUrlDomain(@id)}">
    <xsl:if test="$currentPage/ancestor-or-self::node/@id = current()/@id">
    <!-- we're under the item - you can do your own styling here -->
    <xsl:attribute name="style">font-weight: bold;</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="@nodeName"/>
    </a> --

    </xsl:for-each>

    </xsl:template>
    </xsl:stylesheet>

    Untested, but I reckon it might work :)

    /Josh

  • Bex 444 posts 555 karma points
    Jul 26, 2010 @ 10:43
    Bex
    0

    Wow  didn't know you could put inline code in XSLT... Have done an xslt extension, but not inline!
    If that actually works that gives so many possibilies! :D Keep forgetting I can use C# to do stuff if XSLT isn't doing what I want!

    I will give this ago..! Thanks!

    Umbraco is great, not long been using it but it's making my life so much easier!!

  • Bex 444 posts 555 karma points
    Jul 26, 2010 @ 11:00
    Bex
    0

    Ok, very cool! Inline code!
    Right it will work but now I need to know how to get the actual page name for the url:

    string domain = System.Web.HttpContext.Current.Request.Url.Host.ToString() // returns the right bit
    return domain + umbraco.library.NiceUrl(nodeID); //this returns the full usl as previously

    I have tried passing in @nodeName but this doesn't work because if my page is called "something and something" for the url umbraco renames this to "something-and-something.aspx"
    I know I can replace spaces with "-"'s but there may be other ways in which umbraco renames so it may not be fool proof.
    Does umbraco have a function that calls backe url page name?

     

    Bex

  • Bex 444 posts 555 karma points
    Jul 27, 2010 @ 12:20
    Bex
    0

    Incase anyone else is looking for this.. to get the page name as it would appear in the url I have used the following as found in the core code

     url.FormatUrl(content.Instance.XmlContent.GetElementById(nodeId.ToString()).Attributes.GetNamedItem("urlName").Value);
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies