Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
My content is structured in the following way.
Root Website A Home Page 1 Page 2 Page N Website B Home Website C Home
Each Home document type is connected to an master layout template. In my master layout I try to find the Home node by writing this code.
var home = Model.Content.Siblings().FirstOrDefault(x => x.DocumentTypeAlias == "Home");
This works when im on the Home node, but when I go to ex. Page 1 I get an exception, because Home is not a sibling for Page 1.
Then I tried this.
var home= Umbraco.TypedContentAtXPath("//Home").FirstOrDefault();
And this worked when I was at Website A since it returned the first node. But when at Website B I still got Website A node, and that is wrong.
Any tips on how to solve this?
Originally posted at: http://stackoverflow.com/questions/32809839/find-document-type-in-complex-structure-umbraco-7
I think this is the code that you are looking for:
var home = Model.Content.AncestorOrSelf("Home");
Thanks! I had to change it a bit for it to work.
var home = Model.Content.AncestorOrSelf(2).Children().FirstOrDefault(x => x.DocumentTypeAlias == "Home");
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Find document type in complex structure Umbraco 7
My content is structured in the following way.
Each Home document type is connected to an master layout template. In my master layout I try to find the Home node by writing this code.
var home = Model.Content.Siblings().FirstOrDefault(x => x.DocumentTypeAlias == "Home");
This works when im on the Home node, but when I go to ex. Page 1 I get an exception, because Home is not a sibling for Page 1.
Then I tried this.
var home= Umbraco.TypedContentAtXPath("//Home").FirstOrDefault();
And this worked when I was at Website A since it returned the first node. But when at Website B I still got Website A node, and that is wrong.
Any tips on how to solve this?
Originally posted at: http://stackoverflow.com/questions/32809839/find-document-type-in-complex-structure-umbraco-7
I think this is the code that you are looking for:
var home = Model.Content.AncestorOrSelf("Home");
Thanks! I had to change it a bit for it to work.
is working on a reply...