Posted on zondag 8 maart 2009
Lots of people are aware of those nifty hidden gems in umbraco. And today I'll introduce another one which I came across a few days ago. It's the 'umbracoUrlAlias' property alias. It can be useful in cases where you'd like to restructure some parts of the umbraco content tree. Let's take an news section example and start from this:
-Content
--News
---2009
----4
-----8
------A news item created on March 8th
Assume your client want to keep the tree structure as is (As it makes it easy for him/her to know when posts have been created/updated, but doesn't want users who visit the site to enter the complete path /news/2009/4/8/a-news-item-created-on-martch-8-th.aspx. Instead, the user should be able to enter /news/a-news-item-created-on-march-8-th.aspx.
In this case, 'umbracoUrlAlias' migth become the programmer's best friend. All you need to do is to have an extra property of type 'textstring', and alias = 'umbracoUrlAlias'. For each of the news item, enter news/name-of-the-item (Replace name-of-the-item with the corresponding new item's node name, NO LEADIND SLASH AND DO NOT ADD THE .ASPX EXTENSION) and the news item will also be available from /news/name-of-the-item.aspx.
Ok, got it?
Let's add another example (a real life example I ran into last week) where I am dealing with profiles (Basically, people that register on the site) and projects (People can add any number of projects). Content tree had to be structured as:
-Content
--Profiles
---Profile-1
---Profile-2
----Projects
-----Project-1
----Other stuff folder
---Profile-3
and so...
In this case, 'Project-1' is available from the address /profiles/profile-2/projects/project-1.aspx whereas the client requested that a project is always available from the address /projects/project-1.aspx.
Solution: Again, add a new property of 'textstring' type, alias = 'umbracoUrlAlias' and enter projects/project-1 in the field (for project-1 that is).
Pretty neat stuff, isn't that?
And it's not finished yet. Assume 'Project-1' has a number of child nodes as in following tree structure:
-Content
--Profiles
---Profile-1
---Profile-2
----Projects
-----Project-1
------Child-1
------Child-2
----Other stuff folder
---Profile-3
Both child nodes will be available from /profiles/profile-2/projects/project-1/child-1.aspx (/profiles/profile-2/projects/project-1/child-2.aspx) as from /projects/project-1/child-1.aspx (/projects/project-1/child-1.aspx) without the need to add the property for those child nodes.
Bottom line: It doesn't matter how deep the content is stored inside umbraco, it can always be retrieved using a much more simple url/path if you're adding a 'umbracoUrlAlias' property.
Happy coding!