Get root node of Umbraco 6 multi site install - umbraco

How do you get the root home node of the current site in an Umbraco 6 Multi site install?
The structure is this:
Content
--Home1
--About
--Contact
--Home2
--About
--Contact
--Home3
--About
--Contact

var root = Model.Content.AncestorOrSelf("[YourHomeNodeDocumentType]");
I'm not sure if this is Umbraco 6 syntax, but what you want is that AncestorOrSelf traveersing call. I have many multi-site-multi-lingual setups and I use that all the time. The "or self" portion is fun, in some cases that "root" node is a page.

This works a treat
var rootId = (CurrentPage.Path.Split(','))[1];

It depends if you want a Dynamic Object or a strongly typed DynamicNode Object - but I tend to be in favour of doing it the strongly typed way so I rely on
var root = CurrentModel.AncestorOrSelf(1);

Depending on the version of Umbraco 6 you could use
IPublishedContent rootNode = Umbraco.TypedContentAtRoot().FirstOrDefault();
for a site with a single root node or
IEnumerable<IPublishedContent> rootNode = Umbraco.TypedContentAtRoot();
for as site with multiple root nodes as in your case. These will both work for versions closer to the version 7 track.

I typically use:
Model.Content.AncestorOrSelf(1);
or
IPublishedContent topNode = Model.Content.AncestorOrSelf(1);

Related

Setting unique URL names for nested documents

My content tree goes somewhat like this
Articles
2016
1
Article 1
2
...
2017
1
Article 1
2
...
Is there any way to make Umbraco pick unique URL names for "article 1"?
As for no it gives me "/articles/2016/1/article-1" and "/articles/2017/1/article-1" which by itself is not wrong.
But I would rather have it do like "/articles/2016/1/article-1" and "/articles/2017/1/article-1-1".
The reason for this, is that I'm currently suppressing the year and month in the URL's, but would like to maintain the tree structure in the backoffice.
Nope, not out of the box. By default, the Umbraco UI will ensure unique naming of pages AT THE SAME LEVEL.
So if you already have a page called "Page 1" and try to add one of the same name at the same level, Umbraco will automatically rename it "Page 1 (1)".
It doesn't check the rest of the site though, just the level that you're adding the content on.
To accomplish what you're after, you'd be looking at some kind of event handler on the content service or something similar, and check there for other nodes with the same name at any level.

Order of tabs on home page

Is there a way (or plugin) to order tabs on Jenkins home page? By default, they are sorted in alphabetical order.
Only info I've found is 'no', but it is quite old.
I was looking for a plugin that lets me sort tabs manually a couple of weeks ago. I didn't find anything. So I'm almost sure the answer is still no.
As a workaround we use a prefix like "(0) Viewname A", "(1) Viewname B" etc. in order to have the most important views accessible by one click.
You can add a script to Jenkins, this way it will load each time the view is up.
Go to:
Manage Jenkins->Configure System-> URL of theme JS and add the script.
I used the following script:
sessionStorage["ts_direction::" + window.location.toString() +"::0"] = "type=string&value=3%3Aup"
This order the columns by the 4th column (remember this will affect all of the views!).
example:
You can try Nested View Plugin (a functional plugin based on the hudson.model.TreeView class) which allows grouping job views into multiple levels instead of one big list of tabs.
Alternatively prefix the names with numbers (e.g. 1-Foo, 2-Bar, 3-Baz, etc.).
Prefix the view name with a soft hyphen ­ to make them appear at the end or with a space to make them appear infront ­
shy = String.fromCharCode(173);
chars = ['A','B','Z', shy + 'Z','a',' a','b','z',];
document.body.innerHTML = chars.toString() + '<br/>' + chars.sort().toString()
<html><head></head><body></body></html>

Umbraco Multi-site With Shared Content

If I have 1 Umbraco installation with 4 websites, is it possible to share contents between the sites?
Or is it better to create another website ('repository') that will have all the contents and allow the 4 other websites to retrieve/link contents from this 'repository' website?
There was a good session at Umbraco CodeGarden by CountryWide this year that might be worth watching as it discussed a group in the housing market that have about "40+ different high traffic sites from a single Umbraco installation" but with shared content between many of the sites in the group. You can watch the video here:
http://stream.umbraco.org/video/9921509/40-different-high-traffic-sites-from-a
I'd recommend watching the entire video but if not you can jump to about 25 minutes in to see this topic of discussion. They have a shared content node (+ children).
Simon
I would recommend you stick with your existing websites and not create a repository website. This makes it easier I think to define canonical urls for documents if they are to be displayed on multiple websites. Also makes more sens from a content editor point of view. To reach content from another website, I would use code similar to this (considering Umbraco 7+ here):
// Root nodes
var root = Umbraco.TypedContentAtRoot().First();
var site = Model.Content.AncestorOrSelf("Site");
var lang = Model.Content.AncestorOrSelf("LanguageHome");
var allOtherWebsites = root.Children.Where(x => x.Id != site.Id);
var newsFromAllOtherWebsites = allOtherWebsites.Descendants("News").Where(x => x.Parent.Name.ToLowerInvariant() == lang.Name.ToLowerInvariant());
// Do things with news...
I threw in something for multi-lingual setup also, you can simply remove those if you don't need.
Hope this helps!

Where should I put data like testimonials and addresses in Umbraco?

I am fairly new to Umbraco and I am wondering where I should put pieces of random data.
I have a lot of experience with Sitecore, used it for several years, I am certified etc etc. But now I have to build something with Umbraco. At a first glance Umbraco looks inferior to Sitecore in every way, but I might be wrong about that.
So what I am wondering is, where should I put non-browsable pieces of data that are visible on several places throughout the website? I'd like to create data items in Umbraco for things like Testimonials, Offices? I'd like to have a centralized place in Umbraco where they can be maintained and reference them from a page node. But the way it looks now is that everything has to be on the page node. Which is sort ok, for your average family webpage.
Could someone please shed some light on this?
You could create another node under the man content and call it site settings and store them there that way all pages under the home page are just visible pages on the front end and all data nodes are in a separate area.
There is one property in umbraco that you can add to document types and name it "umbracoNaviHide" (for alias, the name can be anything). This allows wires in automatically to the .IsVisible() method.
var children = Model.Content.Children.Where(x => x.IsVisible());
I find this situation to be very frequent, think of slideshows. When I make an Umbraco website, under my root node I normalle havea Slideshow document type (that contains slides) and I programmatically traverse those to build the slideshow on the home page for example. This Slideshow document has that "umbracoNaviHide" property and I skip it from my menus either using the .IsVisible() method or by manually skipping specific document types.
var menuItems = Model.Content.Children.Where(x => x.DocumentTypeAlias != "Slideshow" && x.DocumentTypeAlias != "Search");
On the other hand, if you are looking for "labels", you can look at "Dictionnary" items under the "Settings" tab.
To directly answer your questions, I reccomend putting non-browsable pieces of data as children of the relevant browsable content node. (But there are other valid ways to do this, it really is up to you and what's best for your content editors.)
Hope this helps.

Multi language, intelligent link conversion

I'm pretty new to Umbraco, so my question may turn out to be pretty simple, but I wasn't able to find any simple guide on it online.
I'm building a simple website with one domain and structure as follows
Content
- en
-- products
-- contacts
- cs
-- produkty
-- kontakty
and so on. My first question is: since I want to accomplish some nice results in SEO, I need to (i) assign meta language to contents of "en" and "cs" nodes, as well as some keywords. How should I do this?
Second: Say that in the future, I decide to add a new language, ex. Russian. So what I would need to do is to make a copy of the "en" node and its contents while the links included in the newly created copy should be rewritten to point at the copy and not the original (original would be /en/anotherpage, which should be rewritten to /ru/anotherpage). Is this possible?
Thanks,
Ondrej
You could build the content structure as a single root node and then have multiple Language homepage nodes directly beneath the content root.
To assign a language, you could create a custom datatype that simply displays all the .Net cultures, e.g. en-GB, fr-FR etc. Include that data type as a field on the language homepage document type and then output this value in the markup on the homepage and each descendant.
In the Language homepage document type, you can add a textstring property called 'umbracoUrlName'. You can then use this property to override the Url name. E.g. So you could call the page www.domain.com/en/ instead of www.domain.com/en/english-home/
With regards to duplicating the site at a later date, this is a difficult one. If the links are created using data types like the media picker and uComponent's multi node tree picker, then you will have no option but to inherit the links from the copied branch. However, if the links are created dynamically in the Razor or XSLT, then you should be able to make the links relative to the Language homepage or the current page. E.g. in XSLT getting the children of the parent language homepage would be something like $currentPage/ancestors-or-self::* [#level = '2']/child::* . In other words you can avoid hard coding links by using a clever bit of relative traversal.
This should give you a good start on creating multilingual sites in Umbraco
http://our.umbraco.org/wiki/how-tos/running-multi-lingual-sites-under-a-single-domain
If you was to create a Russian version in the future you would do exactly what you have mentioned above, its that easy.
To set the language meta data I would store this in a property on the langauge root node eg: /en/ to get the language page property from any page:
var langNode = new Node(int.Parse(node.Path.Split(',')[1]));
langNode.GetProperty("languageCode");
As for copying the English version to the Russian version and fixing all the links, I'm not aware of anything in umbraco to help you with this, you could write something yourself to find all the links and node references and fix them. you could use the relations API to keep track of what was copied from where to where. You'll need to be aware that you could end up copying nodes more than once.
If you don't have too much data, manually fixing links may be quicker.

Resources