djscorch, you are indeed right, the cheat sheet shows methods that simply do not exist in Umbraco source! However, I thought the method looked useful (and spent like 15mins trying to debug why it didn't work as expected) and so I implemented this using breadth first search. I've shared the patch on gist; after you recompile you need to replace umbraco.MacroEngines.dll with the improved version.
Let me know if you encounter any problems, this was only briefly tested for our use case.
Depending on what you need, just do DescendantsOrSelf (WITH the "s") and add .First() or .Last() in the end. I wouldn't recommend customized versions of the Razor engine as it will block your upgrade path to newer versions of Umbraco.
> I wouldn't recommend customized versions of the Razor engine as it will block your upgrade path to newer versions of Umbraco.
Perhaps true, but we maintain a set of over a dozen little patches for our internal use and regularly apply them to newer versions of Umbraco. Plus Umb v5 is meant to be a whole different codebase which will trow all of them out the window anyway!
Ps. A little odd that nForum does not have the "Quote" button... seems like a major shortcoming compared to other forums.
Exactly, that's what I meant when I said that v5 will throw all our patches out the window :-) We've been meaning to share them with the team for a while but never seem to have enough time to read up on the procedure required to do that... and resort to sharing them with the community in threads such as this one.
Ps. I thought nForum was based on our.umbraco... but can see in page source that it's most likely powered by uForum. Shame about lack of quoting all the same ;-)
Is there a problem with DescendantOrSelf in 4.7.0?
<div class="latest-mixes">
<ul>
@{
var mixNode = @Model.DescendantOrSelf("MixArchive");
}
</ul>
</div>
Gives me the error Error loading Razor Script homeMixes.cshtml Cannot invoke a non-delegate type.
Am i missing something?
Works for me in 4.7.1. Remember if you want a collection of nodes, then it's DescendantsOrSelf
I just want the one node, i'm having a similar issue in a 4.7.1 build.
var mixNode = @Model.DescendantOrSelf("MixArchive");
doesn't seem to return anything. Could I see your syntax?
It's still DescendantsOrSelf with an "s" before Or :-)
Not according to Umbraco 4.7.1 Razor + DynamicNode Cheat Sheet it's not...
http://our.umbraco.org/projects/developer-tools/razor-dynamicnode-cheat-sheet
djscorch, you are indeed right, the cheat sheet shows methods that simply do not exist in Umbraco source! However, I thought the method looked useful (and spent like 15mins trying to debug why it didn't work as expected) and so I implemented this using breadth first search. I've shared the patch on gist; after you recompile you need to replace umbraco.MacroEngines.dll with the improved version.
Let me know if you encounter any problems, this was only briefly tested for our use case.
Depending on what you need, just do DescendantsOrSelf (WITH the "s") and add .First() or .Last() in the end. I wouldn't recommend customized versions of the Razor engine as it will block your upgrade path to newer versions of Umbraco.
djscorch maybe you could describe what you want to achieve?
I just wanted to select a specific node, using the nodeTypeAlias, seems like this is possible with DescendantsOrSelf and the .First().
I'll give it a try and get back, at least I know I wasn't going crazy and DescendantOrSelf really doesn't work!
Cheers guys.
Hi djscorch,
You can also try to remove the "@" in front of Model, since you already have an @ before the curly brackets:
Cheers,
Michael.
> I wouldn't recommend customized versions of the Razor engine as it will block your upgrade path to newer versions of Umbraco.
Perhaps true, but we maintain a set of over a dozen little patches for our internal use and regularly apply them to newer versions of Umbraco. Plus Umb v5 is meant to be a whole different codebase which will trow all of them out the window anyway!
Ps. A little odd that nForum does not have the "Quote" button... seems like a major shortcoming compared to other forums.
You wouldn't upgrade from v4 to v5 anyway..
If you have fixes, I'm sure the umbraco team would be very happy to accept them, maybe you could try and get them into the core!
Ps. This is not nForum. It's a custom forum written specifically for our.umbraco.
Exactly, that's what I meant when I said that v5 will throw all our patches out the window :-) We've been meaning to share them with the team for a while but never seem to have enough time to read up on the procedure required to do that... and resort to sharing them with the community in threads such as this one.
Ps. I thought nForum was based on our.umbraco... but can see in page source that it's most likely powered by uForum. Shame about lack of quoting all the same ;-)
is working on a reply...