Multi-Node Tree Picker: help with example code (in Razor)?
Hi all,
Complete beginner to Umbraco & Razor here. I'm using the Multi Node Tree Picker data type to grab some content from selected pages, using Razor. The problem is I can't seem to grab anything from the nodes/pages I've selected. I've used this example for getting values using the data type and nothing is shown:
<ul> @foreach (var x in Model.refKursus) { <li>@x.InnerText</li> } </ul>
Ideally, I'm trying to get a snippet of body text (via rich text editor), the page url and page title from each of the selected pages, which I can then display on another page.
So far I've got the datatype installed, and the datatype settings seem to work (from other recommendations). But with the methods I've already tried, nothing is rendering. Obviously as I'm brand new to this, there's a lot of inconsistency in what I've tried so far, but I would really appreciate any suggestions to get this working!
This (as far as i can gather) is setting the node from the list as the current node from which you can then access your properties?? Does that make sense?
If anyone else can comment or shed light please do -
Seans example is spot on, here's some example code to list the contents of a "footer menu" property - which itself is a multi-node-picker for content nodes.
This code was fantastic in helping me figure out how to create the multi-node-picker. The only problem I'm having right now is it's not showing up on child pages. The home page is fine, it works great, but as soon as I go to a different page the navigation dissappears.
Trying to get list of nodes selected by multi-node picker in partial view (umbraco 6 mvc).
My solution:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{ var rootNode = Model.Content.AncestorOrSelf();
var featuredPostsVal = (Umbraco.Core.Dynamics.DynamicXml)rootNode.GetPropertyValue("featuredPosts"); //this is my MNP field //the ugly part String[] featuredIds = new String[featuredPostsVal.Count()];
int i = 0;
foreach (var featuredPostId in featuredPostsVal)
{
featuredIds[i] = featuredPostId.InnerText;
i++;
}
var featuredPosts = Umbraco.TypedContent(featuredIds); }
I still think the best way to do this is to use the PropertyValueConverters project. Not sure what version you're on, but there's a version specifically for v7 if you're using that. Then you can use the code snippet Pavel posted above.
Multi-Node Tree Picker: help with example code (in Razor)?
Hi all,
Complete beginner to Umbraco & Razor here. I'm using the Multi Node Tree Picker data type to grab some content from selected pages, using Razor. The problem is I can't seem to grab anything from the nodes/pages I've selected. I've used this example for getting values using the data type and nothing is shown:
Ideally, I'm trying to get a snippet of body text (via rich text editor), the page url and page title from each of the selected pages, which I can then display on another page.
So far I've got the datatype installed, and the datatype settings seem to work (from other recommendations). But with the methods I've already tried, nothing is rendering. Obviously as I'm brand new to this, there's a lot of inconsistency in what I've tried so far, but I would really appreciate any suggestions to get this working!
Hi MM,
I am a bit of a newbie to this too but have been looking into this a bit as well today and may have found a solution.
Try:
@{
var theNode = "";
foreach (var x in Model.refKursus) {
theNode = @x.InnerText;
var yourItem = @Model.NodeById((@theNode));
@yourItem.Url
}
}
This (as far as i can gather) is setting the node from the list as the current node from which you can then access your properties?? Does that make sense?
If anyone else can comment or shed light please do -
Cheers,
Kenny
Hi mmmoustache
Kenny Burns code looks right. You should be able to grab the node from a single line
@foreach(var item in Model.refKursus) {
var node = Library.NodeById(item.InnerText);
@node.Name @node.Url
}
Seans example is spot on, here's some example code to list the contents of a "footer menu" property - which itself is a multi-node-picker for content nodes.
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
<nav>
@if(Model.HasValue("footerMenu")){
<ul>
@foreach(var item in Model.footerMenu){
var node = Library.NodeById(item.InnerText);
<li>
<a href="@node.Url" title="@node.Name">@node.Name</a>
</li>
}
</ul>
}
</nav>
}
This code was fantastic in helping me figure out how to create the multi-node-picker. The only problem I'm having right now is it's not showing up on child pages. The home page is fine, it works great, but as soon as I go to a different page the navigation dissappears.
I'm using nearly identical code as above (Drew).
Any advice?
Got if figured out. Since I'm planning on using this for a main navigational element it was critical to find an answer.
Here's my code.
Trying to get list of nodes selected by multi-node picker in partial view (umbraco 6 mvc).
My solution:
Any ideas how to make it more simple/convenient?
Hi,
You could extract that into a helper method to mask the ugliness :)
But you should check out PropertyEditorConverters. Jeavon made a package that has support for a lot of datatypes: http://our.umbraco.org/projects/developer-tools/umbraco-core-property-editor-converters
This would let you do the following (taken from docs):
Hope this helps,
Tom
Hi Tom,
PropertyEditorConverters is exactly what I needed.
Replaced all ugliness with one line :)
Thanks!
Hi guys
I am working on a uComponents Multinode tree picker razor. I can't get the razor to fetch the url or the name, but it gets the 3 pages as it should.
UPDATE: Got it working now, it was a wrong setting on my datatype :)
/Michael
Michael,
What was the solution? I am trying to output pageTitles from nodes that are selected via the uComponents multinode tree picker on a seperate node.
Hey Steve,
I still think the best way to do this is to use the PropertyValueConverters project. Not sure what version you're on, but there's a version specifically for v7 if you're using that. Then you can use the code snippet Pavel posted above.
Sorry to dredge up an old thread but for folks using Umbraco v7.x I found the following snippet to work in a Partial Macro View
I have a "promoPanelPicker" which picks content. "Adapted" from http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors-v7/Multinode-Treepicker Hope this helps someone (at least probably me when I Google it again in about two weeks).
@Steve Morgan,
This was actually perfect for my needs. Thanks for dredging this up. It helped me out.
is working on a reply...