Seb, just go from the top and work down. If you need to implement more functionality in the future of tweek what nodes you are finding. That will be the simple way imo
but you should be able to use @Model.Content.AncestorsOrSelf(2).Where("Visible").Name (if you take this route in WebMatrix or VS, you should get Intellisense)
This will return node name at level 2. If you need to go up 2 levels, @Model.Content.Up(2).Name will return it.
Check your @Using statement at the top of the page, it should be @Umbraco.MacroEngines or something like that, sorry as I say I use MVC.
You can also have a look at this razor walkthrough, it is still valid and should help you.
Howto: Get Ancestor at level 2 of currentpage ?
How do I do this
In Razor ?
Hi, What is umbracoNaviHide? Is that a property? What type is it?
DynamicNode rootNode = new DynamicNode(-1); // right at the top of the tree
DynamicNode HomeNode = rootNode(-1); //the first node in my tree
//Then do a foreach
Foreach(DynamicNode ctxNode = RootNode.Descendants().Where(x=>x.Level == 2 && x.getProperty("umbracoNaviHide).Value == 1)
{
Do something with your nodes :).
}
Dang ... that was a lot of code for replacing an XSLT one liner.
Guess that's why I'm still crawling back to XSLT :)
umbracoNaviHide is, or should be, property of the type boolean.
But I don't know if it's the case in Razor, but in the Umbraco XML a boolean can be 1, 0 or "" (empty), which is why I use the not(umbracoNaviHide=1).
And by the way.
Why use a foreach when it only returns a single node ?
Hi Sebastian
Don't know XSLT but from what I can see of it, how about
@CurrentPage.AncestorsOrSelf(2).Where("Visible").Name
umbraco NaviHide is used because it returns on Visible as above.
So current page up 2 levels, not hidden from navigation, node name, is what it should return.
Gary
I get this error when I try to save the file within the Umbraco backoffice
The name 'CurrentPage' does not exist in the current context
If I skip testing I don't get anything ...
Ok
What version of Umbraco? Webforms or MVC?
or try @Model.AncestorsOrSelf etc. . .
If that does not compile, will need version etc to help more
G
Gary: Question.
The 'AncestorsOrSelf(2)' does go to level 2 or does it go up 2 levels from the level of currentPage ?
Yea thats a good point that was from a model i had. If you are in a razor view then you could do @Model....
You dont need to do a foreach for a single node.
At the top of your razor page: @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
Then:
int umbracoNaviHide = 0;
Int32.Parse(@Model.Context.getProperty("umbracoNaviHide").Value.ToString(), out umbracoNaviHide); parse the bool value
DynamicNode rootNode = new DynamicNode(-1); // right at the top of the tree
string myvalue = rootNode.Descendants().Where(x=>x.Level == 2 && umbracoNaviHide == 1)
Something like that :)
}
Seb, just go from the top and work down. If you need to implement more functionality in the future of tweek what nodes you are finding. That will be the simple way imo
Gary: I'm using Umbraco v6.0.3 webforms
Hi
I use MVC,
but you should be able to use @Model.Content.AncestorsOrSelf(2).Where("Visible").Name (if you take this route in WebMatrix or VS, you should get Intellisense)
This will return node name at level 2. If you need to go up 2 levels, @Model.Content.Up(2).Name will return it.
Check your @Using statement at the top of the page, it should be @Umbraco.MacroEngines or something like that, sorry as I say I use MVC.
You can also have a look at this razor walkthrough, it is still valid and should help you.
http://umbraco.com/follow-us/blog-archive/2011/2/23/umbraco-47-razor-feature-walkthrough-%E2%80%93-part-1.aspx
Best regards
Gary
Uhhh ... WebMatrix or VS ??
I'm on a mac, so I ain't going there :)
But my file has '@inherits umbraco.MacroEngines.DynamicNodeContext' in the top.
I've tried
and
But none of them gave me any output.
I think I'll leave the Razor stuff to the backend developers.
But thanx alot for your help guys.
Hi
I know this is an old one, but I thought I would leave a comment for future readers, since I just had the exact same problem. I tried to do:
and it didn't work. Just gave me an error. Then it occurred to me that I had written "Ancestors" - plural. It should of course by singular.
Cheers
Bjørn
is working on a reply...