Jump to content

Umbraco/Samples and Articles/Templates/URLsubstitution

From Wikibooks, open books for an open world

What is it?

[edit | edit source]

Umbraco URL's look like this:
'http://www.mysite.org/subpage1/subpage1-1/somedocument1.aspx'
You can make it to look like:
'http://www.mysite.org/somedocument1.aspx'
or even
'http://www.mysite.org/somedocument'

Reasons

[edit | edit source]
  • You need to give an "easy to remember" link to the customer
  • Different charactersets.

The document name field by default is converted to an URL. If you have a document named "Странитса", it will be converted to an unacceptable link for www and the structure of your site will be broken.

Solution

[edit | edit source]
  • For documents that need a new "link", the document type must be changed.

Add a new property with an alias umbracoUrlAlias, the property name is important. *incomplete - what sort of property (i.e.: label, tags, textstring)?*

  • Document now has a new field, where the URL alias can be written.

When substituting url's for several nodes, maybe even in full branch, you must type full ascending path, otherwise links will be broken.
Example: If you have the first subnode named Frontpage with UrlAlias Pagefront and its child Products with UrlAlias Items, type in Products page alias field:

Pagefront/Items (do not add .aspx)

Additional hints

[edit | edit source]
  • Navigation

When you replaced the url to get new and working links and you use XSLT transformations for generating a site navigation or sitemap, modifications are needed in XSLT file. Look at the following sample how this could be done:

<xsl:choose>
  <xsl:when test="data [@alias = 'umbracoUrlAlias'] != ''">
    <a href="{concat('/', data [@alias = 'umbracoUrlAlias'],'.aspx')}"><xsl:value-of
    select="@nodeName"/></a>
  </xsl:when>
  <xsl:otherwise>
    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of
    select="@nodeName"/></a>
  </xsl:otherwise>
</xsl:choose>	


WILL CONTINUE ASAP