Querying the content structure

Topics: General
Apr 11, 2011 at 3:03 PM

Is it possible to query the content of the CMS to create navigation menus etc as you can with N2 CMS?

                <%
                    foreach (var item in N2.Find.StartPage.Children.Where(x => x.Visible == true))
                    {%>
                <li class="<%= item.Title.ToLower().Replace(" ","-") %>"><a href="<%=ResolveUrl(item.Url)%>" class="<%=item.Url == Model.CurrentItem.Url ? "selected" : "" %>"><span class="displace">
                    <%=item.Title %></span></a></li>
                <%}%>

Apr 11, 2011 at 3:24 PM

Technically yes but I don't think there's a way to access the IContentManager directly from your view.

You'd need to do so by creating a custom widget and push the menu into the your model in the ContentPartDriver.

However - I'm not sure exactly what you're after but have you seen the Advanced Menu module which lets you create multiple hierarchical menus? It also has an option to populate the menu from existing content.

See: http://www.orchardproject.net/gallery/List/Modules/Orchard.Module.Szmyd.Orchard.Modules.Menu

Apr 11, 2011 at 4:01 PM

Hi Pete

Thanks for your reply. Are there any examples or tutorials on how to create menus by creating a custom widget etc?

Apr 11, 2011 at 4:16 PM

Well the Advanced menu that I just linked to has examples of that. You could start there :)

Apr 18, 2011 at 2:47 PM
Edited Apr 18, 2011 at 2:48 PM

Hi Pete

I finally got round to installing Orchard and the Advanced Menu module.

The Advanced Menu module seems pretty complex and there are a lot of files installed with the menu.

I tried creating a new Menu then filling it with existing content and got a 404 Error at page "http://localhost:11889/Admin/Navigation/Sub%20Menu/Fill"

So I tried to delete the menu and got an "A required anti-forgery token was not supplied or was invalid." exception.

Any ideas as to whats going on?

BG

Apr 18, 2011 at 3:04 PM

I ran into a few errors and a number of people have reported problems in the comments page on Piotr's site. I'm hoping there will be an update soon. But I'm kind of working on my own system now anyway which works in a slightly different way.

In the meantime you can still use the default Navigation system, every time you add a Page you can tick "add to main menu" so it's pretty easy. Look at the Menu.cshtml and MenuItem.cshtml files in Orchard.Core/Shapes/Views if you need to customise the rendering.

You could also just query the ContentManager in your view with:

 

@{
    WorkContext.Resolve<Orchard.ContentManagement.IContentManager>().Query();
}

But you'll need to gain some understanding of how content items work and how you can pull out the correct data (RoutablePart). You should probably work through the "hello world" module tutorial and look at some other modules code first to learn how it all fits together.

 

 

Apr 18, 2011 at 3:12 PM

Thanks for your help Pete.