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
This code is from a Razor Macro on a previous version of Umbraco - it works.
In Umbraco 6 there's no such thing as AncestorsOrSelf (or so VS tells me)
var currentPage = @Model; //Will walk up the tree to the last ancestor node aka RootNode var rootNode = currentPage.AncestorsOrSelf()[0];
So - where has it gone wrong - I can find loads of documentation and reference to it, I've tried some variations, but I can't seem to find it.
I've got this now in a "MacroPartials" and it's supposed to be a simple Navigation script.
Where's it gone?
Hi Ian
Yes, but not yet, was left private, use AncestorOrSelf, should give you what you require for now.
Hope it helps G
I've just written a function which loops through the parent until it's at the top - does the same job.....
IPublishedContent getRootNode(IPublishedContent node) { while (node.Parent != null) { node = node.Parent; } return node; }
You can try this solution:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using System.Linq
@{
var rootItem = this.Current.AncestorOrSelf(1);
var menuItems = this.Current.AncestorOrSelf(1).Children.Where(p => p.HasProperty("umbracoNaviHide") &&
(string)p.GetProperty("umbracoNaviHide").Value != "1").ToList();
menuItems.Insert(0, rootItem);
}
<div id="midt_local">
<div id="meny_top_local">
<div id="knappe-container_local">
<ul id="knappe-menu_local">
@foreach (umbraco.MacroEngines.DynamicNode item in menuItems)
{
bool currentPage = item.Id == this.Current.Id;
<li>
<a href="@item.Url" @Html.Raw(currentPage ? "class=\"current\"" : string.Empty)>
@item.GetProperty("umbnavigationName").Value
</a>
</li>
</ul>
</div>
Thanks @Ian Smedley! I was able to fit your code into a perfect helper function for me to get the parent "section" of each of me pages while stopping before crawling up to the homepage. Exactly what I needed thanks again!
@helper getRootNode(IPublishedContent node) { while (node.Parent.Id != 1115) { node = node.Parent; } <h1>@node.Name</h1>
Then in my markup I can just use
<div class="headline container"> <div class="row"> <div class="page-title twelvecol"> @getRootNode(CurrentPage) </div> </div> </div>
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
V6 - MVC Razor Where has AncestorOrSelf Gone
This code is from a Razor Macro on a previous version of Umbraco - it works.
In Umbraco 6 there's no such thing as AncestorsOrSelf (or so VS tells me)
So - where has it gone wrong - I can find loads of documentation and reference to it, I've tried some variations, but I can't seem to find it.
I've got this now in a "MacroPartials" and it's supposed to be a simple Navigation script.
Where's it gone?
Hi Ian
Yes, but not yet, was left private, use AncestorOrSelf, should give you what you require for now.
Hope it helps G
I've just written a function which loops through the parent until it's at the top - does the same job.....
You can try this solution:
@inherits umbraco.MacroEngines.DynamicNodeContext
@using System.Linq
@{
var rootItem = this.Current.AncestorOrSelf(1);
var menuItems = this.Current.AncestorOrSelf(1).Children.Where(p => p.HasProperty("umbracoNaviHide") &&
(string)p.GetProperty("umbracoNaviHide").Value != "1").ToList();
menuItems.Insert(0, rootItem);
}
<div id="midt_local">
<div id="meny_top_local">
<div id="knappe-container_local">
<ul id="knappe-menu_local">
@foreach (umbraco.MacroEngines.DynamicNode item in menuItems)
{
bool currentPage = item.Id == this.Current.Id;
<li>
<a href="@item.Url" @Html.Raw(currentPage ? "class=\"current\"" : string.Empty)>
@item.GetProperty("umbnavigationName").Value
</a>
</li>
}
</ul>
</div>
</div>
</div>
Thanks @Ian Smedley! I was able to fit your code into a perfect helper function for me to get the parent "section" of each of me pages while stopping before crawling up to the homepage. Exactly what I needed thanks again!
Then in my markup I can just use
is working on a reply...