This is quite tricky to explain, but here goes... I have a website with 2 content trees:
- Website - News Page - Bios Page - etc
- Data - News Items - News Item #1 - News Item #2 - Bios Items - Bio #1 - Bio #2
Basically i've separated site structure from content... so for editors to update site content, most of the time they'll do it in the Data node, and to edit page content, they'll do it in the Website node. The website node controls URLs.
This is easy to do when the data items don't need their own pages (for example, the bios all get laid out on the same page - the Bios Page - so they don't need to have separate URLs.
The news section is a little tricker. The News Page will show a list of items under the News Items data tree, showing only headers and teasers from the relevant news items, and a link to view the full news item. I now need to create a macro on the News Page, which will show either the list (if /News.aspx is the current page), or the news item page if a news item link is clicked. I know i could do this quite easily using a querystring (eg: /News.aspx?id=2345), however I'd like the news items to have nice urls (eg: /News/News-item-1.aspx). The only way i know how to achieve this is by having the news items under the News Page node under Website, instead of under a separate tree... but i'm hoping to keep the actual data in the separate tree.
Any ideas how i can achieve this? I guess I'd need a way for all pages in the /News/ url space to call a specific macro, and then perhaps get the page name and match it to a data node. But i have no idea how to do this.. hoping somebody has done it before and can show me how?
we have pretty much the same setup for most of our sites. Usually that data section contains only nodes that don't have a template associated with it. However in certain cases (like the news items) there will be an exception. To get the nice url I make use of the 'Manage hostnames' feature in the context menu on the 'News items' node. Set this to 'yourhostname.com/news' and all child nodes will automatically pick up 'yourhostname.com/news/[news item node url]'.
As the parent 'News items' will also get a url in this case I mostly implement the 'News Page' node as a redirect node so it goes directly into the data section (which means the 'News items' node would have the news list template).
The beauty of this - how I recently found out - is that you can provide multiple hostnames, e.g. 'yourotherhostname.com', and as long as you keep relative links on your page (or implement some business logic around that) you can access the news items from different sites with different hostnames in one Umbraco installation and the user will stay on the same hostname. Beautiful.
A code approach could be to create a iNotFound handler for this. So when a user accesses the /News/News-item-1.aspx url, your handler can determine that the "currentPage is actually the /News.aspx page, and then look in your data section to identify which news item you want to return for the url, and then set a contextItem with the ID of that node, and possibly also set the altTemplate that should be used for displaying that item.
The big difference compared to Sascha's approach is that you keep the "currentNode" inside your website section, which will probably make it easier to handle navigation and such.
Thanks for the advice guys... both were excellent suggestions.
On thinking about this further, i have decided to keep the news items in the main tree. The reason for this is because the main tree is where all web pages get created. By keeping news items in there, its keeping consistent with this approach, and i think it'll be easier for the client to understand.
I'll definitely keep your answers in my knowledge base for future reference.. thanks heaps
By the way, i'd thought about the hostnames option, however didn't realise you could put a folder name in a hostname. So i was thinking about creating a news.domain.com sub domain to go the hostname route.. but this was far from ideal... nice to know hostnames can include folders - that's super handY :)
many thanks for the hint for using an INotFound handler for this, haven't thought about it, but looks like the better solution to me, will give that a try now. :)
Nice URL from a Doc not in Main Tree
This is quite tricky to explain, but here goes... I have a website with 2 content trees:
- Website
- News Page
- Bios Page
- etc
- Data
- News Items
- News Item #1
- News Item #2
- Bios Items
- Bio #1
- Bio #2
Basically i've separated site structure from content... so for editors to update site content, most of the time they'll do it in the Data node, and to edit page content, they'll do it in the Website node. The website node controls URLs.
This is easy to do when the data items don't need their own pages (for example, the bios all get laid out on the same page - the Bios Page - so they don't need to have separate URLs.
The news section is a little tricker. The News Page will show a list of items under the News Items data tree, showing only headers and teasers from the relevant news items, and a link to view the full news item. I now need to create a macro on the News Page, which will show either the list (if /News.aspx is the current page), or the news item page if a news item link is clicked. I know i could do this quite easily using a querystring (eg: /News.aspx?id=2345), however I'd like the news items to have nice urls (eg: /News/News-item-1.aspx). The only way i know how to achieve this is by having the news items under the News Page node under Website, instead of under a separate tree... but i'm hoping to keep the actual data in the separate tree.
Any ideas how i can achieve this? I guess I'd need a way for all pages in the /News/ url space to call a specific macro, and then perhaps get the page name and match it to a data node. But i have no idea how to do this.. hoping somebody has done it before and can show me how?
Thanks heaps
Greg.
Hi Greg,
we have pretty much the same setup for most of our sites. Usually that data section contains only nodes that don't have a template associated with it. However in certain cases (like the news items) there will be an exception. To get the nice url I make use of the 'Manage hostnames' feature in the context menu on the 'News items' node. Set this to 'yourhostname.com/news' and all child nodes will automatically pick up 'yourhostname.com/news/[news item node url]'.
As the parent 'News items' will also get a url in this case I mostly implement the 'News Page' node as a redirect node so it goes directly into the data section (which means the 'News items' node would have the news list template).
The beauty of this - how I recently found out - is that you can provide multiple hostnames, e.g. 'yourotherhostname.com', and as long as you keep relative links on your page (or implement some business logic around that) you can access the news items from different sites with different hostnames in one Umbraco installation and the user will stay on the same hostname. Beautiful.
Hope that was what you were looking for,
Sascha
A code approach could be to create a iNotFound handler for this. So when a user accesses the /News/News-item-1.aspx url, your handler can determine that the "currentPage is actually the /News.aspx page, and then look in your data section to identify which news item you want to return for the url, and then set a contextItem with the ID of that node, and possibly also set the altTemplate that should be used for displaying that item.
The big difference compared to Sascha's approach is that you keep the "currentNode" inside your website section, which will probably make it easier to handle navigation and such.
Thanks for the advice guys... both were excellent suggestions.
On thinking about this further, i have decided to keep the news items in the main tree. The reason for this is because the main tree is where all web pages get created. By keeping news items in there, its keeping consistent with this approach, and i think it'll be easier for the client to understand.
I'll definitely keep your answers in my knowledge base for future reference.. thanks heaps
By the way, i'd thought about the hostnames option, however didn't realise you could put a folder name in a hostname. So i was thinking about creating a news.domain.com sub domain to go the hostname route.. but this was far from ideal... nice to know hostnames can include folders - that's super handY :)
Hi Morton,
many thanks for the hint for using an INotFound handler for this, haven't thought about it, but looks like the better solution to me, will give that a try now. :)
Sascha
is working on a reply...
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.