Custom field - refer to in layer rules

Topics: Customizing Orchard, General
Apr 25, 2013 at 2:43 PM
Hi there

I have created a custom field on my page called 'Page type'.
I have set this up as a text field, although if I can get filtering working I may change it to an enumeration field.

I would like to refer to the value of this 'Page type' in my layer rules but I am unsure how to do this.

Any help would be very much appreciated.

Many thanks,
Apr 25, 2013 at 3:53 PM
Could you describe what the intent of the layer rule is?
For example, are you trying to write a layer rule that returns true when the "Page type" field has a specific value?
Apr 25, 2013 at 4:08 PM
Thanks for your reply. What I am trying to do is the following:-

I have a main navigation menu for my website and wanted to create sub-menus for pages depending on which group they belong to.
I have set this up and it is working at the minute. I have a layer called Developer group and the rule for this is 'url("~/land-acquisition") or url("~/development-viability-appraisals") or url("~/section-106") or url("~/affordable-housing")'. I have then set up a sub-menu for the 'Developers' group and created a menu widget to display this sub-menu on the Developer layer only. (I also have other specific layers and pages).

This was all working great until I realised this way was flawed because when you add a new page or change a page name, the layer rule also has to be updated. Therefore I have added a 'Page type' field to a page and would like to give this values such as 'Developer, Investment, Occupier'. The layer rule will then look at the value of 'Page type' to decide which sub-menu is shown on the page.

Hope this makes sense and there is probably a much better way of doing this, I am new to using Orchard!

Thanks in advance,
Apr 25, 2013 at 4:45 PM
Ok. I don't think there's a Layer rule out of the box that enables you to compare against a field of the "current" content item being rendered ("current" being the content item associated with the current url). One could write such a layer rule of course.

If you have just a small number of "top-level" pages such as "~/land-acquisition" and "~/affordable-housing", and they contain "sub-level" pages, for which you want to activate the layer, you could use wild cards if the url structure mimics the hierarchy. For example, if you have a sub-page at "~/affordable-housing/details", you could write a layer rule such as ""~/affordable-housing*" (notice the asterisk).

Alternatively, you could get away with having just 2 Menu Widgets: 1 for the main menu, and another for the sub menu.
Configure the second menu widget to only render 2nd level menu items. This will render the entire structure starting from level 2 for the currently selected main menu item.
Apr 29, 2013 at 9:46 AM
thanks for your reply. I have about 6 menu items each of which need different sub-menus.

I may try the 2nd level menu item idea.

If I wanted to have a go at writing a layer rule which basically says 'Check the value of 'Page type' and if it is Developers display Developers menu - any ideas?

Thanks for you help,
Apr 29, 2013 at 6:56 PM
Check existing modules implementing layer rules, on the gallery.
May 3, 2013 at 12:14 AM
Edited May 3, 2013 at 12:18 AM
Maybe make the filter, as in the ISSUE TRACKER on CodePlex?
The main question is what would dynamically load the contents without changing the URL. It's hard to imagine using any module to do this, this, any recommendations can be useful.