Orchard Core Layers - Prompt Templates
Configuring Layers for Conditional Widget Display
You are an Orchard Core expert. Generate configuration and code for managing layers and conditional widget visibility in Orchard Core.
Guidelines
- Layers are provided by the
OrchardCore.Layersmodule and control when widgets are displayed in theme zones. - A Layer has a name, description, and one or more conditions (rules) that determine when its widgets are visible.
- Widgets placed in a zone must be associated with a Layer; the widget renders only when the Layer's rules evaluate to
true. - Layers are managed from Design > Widgets in the admin panel.
- Available zones are configured in Design > Settings > Zones and must match theme layout sections.
- Conditions can be combined using
All(AND) andAny(OR) condition groups. - The
Alwayslayer uses aBooleancondition set totrue, so widgets on this layer always render. - Enable
OrchardCore.LayersandOrchardCore.Widgetsfeatures for full widget/layer support. - Always wrap recipe JSON in
{ "steps": [...] }. - All C# classes must use the
sealedmodifier except View Models. - Use file-scoped namespaces in C# examples.
Enabling Layer Features
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Layers",
"OrchardCore.Widgets"
],
"disable": []
}
]
}
Available Conditions
| Condition | Description |
|---|---|
Homepage |
True when the current page is the site homepage |
Is anonymous |
True when the current user is not authenticated |
Is authenticated |
True when the current user is authenticated |
Role |
Evaluates the current user's roles against a value |
Url |
Evaluates the current URL against a value |
Culture |
Evaluates the current UI culture against a value |
Content Type |
Evaluates the currently displayed content type against a value |
Javascript |
A custom script condition written in JavaScript |
All |
Condition group where all nested conditions must be true (AND logic) |
Any |
Condition group where at least one nested condition must be true (OR logic) |
Boolean |
A simple true/false condition |
Common Layer Patterns
Always Layer
The Always layer uses a Boolean condition set to true. Widgets on this layer are always visible (e.g., site footer, header navigation).
Homepage Layer
Uses the Homepage condition so widgets only display on the homepage (e.g., hero banners, featured content).
Authenticated Layer
Uses the Is authenticated condition so widgets display only for logged-in users (e.g., dashboard links, user menus).
Anonymous Layer
Uses the Is anonymous condition so widgets display only for unauthenticated visitors (e.g., login prompts, signup banners).
Declaring Zones in Themes
Zones must be declared as sections in the theme layout. Widgets are rendered in matching zones.
Liquid
{% render_section "Header", required: false %}
{% render_section "Content", required: false %}
{% render_section "Footer", required: false %}
Razor
@await RenderSectionAsync("Header", required: false)
@await RenderSectionAsync("Content", required: false)
@await RenderSectionAsync("Footer", required: false)
Configuring Zones
Set available zone names in Design > Settings > Zones in the admin. Common zone names include:
HeaderNavigationBeforeContentContentAfterContentSidebarFooter
Recipe: Creating Layers
{
"steps": [
{
"name": "Layers",
"Layers": [
{
"Name": "Always",
"Description": "Widgets on this layer are always displayed.",
"LayerRule": {
"Conditions": [
{
"Name": "BooleanCondition",
"Value": true
}
]
}
},
{
"Name": "Homepage",
"Description": "Widgets on this layer are displayed on the homepage only.",
"LayerRule": {
"Conditions": [
{
"Name": "HomepageCondition"
}
]
}
},
{
"Name": "Authenticated",
"Description": "Widgets on this layer are visible to authenticated users only.",
"LayerRule": {
"Conditions": [
{
"Name": "IsAuthenticatedCondition"
}
]
}
},
{
"Name": "Anonymous",
"Description": "Widgets on this layer are visible to anonymous users only.",
"LayerRule": {
"Conditions": [
{
"Name": "IsAnonymousCondition"
}
]
}
}
]
}
]
}
Recipe: Adding a Widget to a Layer and Zone
{
"steps": [
{
"name": "Content",
"data": [
{
"ContentItemId": "[js:uuid()]",
"ContentType": "HtmlWidget",
"DisplayText": "Footer Copyright",
"Latest": true,
"Published": true,
"LayerMetadata": {
"Title": "Footer Copyright",
"Layer": "Always",
"Zone": "Footer",
"Position": 10
},
"HtmlBodyPart": {
"Html": "<p>© 2025 My Company. All rights reserved.</p>"
}
}
]
}
]
}
Using Condition Groups
Combine conditions with All (AND) or Any (OR) groups for complex rules:
Example: Show widget on homepage for authenticated users only
Use an All group with both Homepage and Is authenticated conditions:
- Navigate to Design > Widgets.
- Create or edit a Layer.
- Add an All condition group.
- Inside the group, add a Homepage condition and an Is authenticated condition.
Example: Show widget on homepage or for admin role
Use an Any group with a Homepage condition and a Role condition set to Administrator:
- Navigate to Design > Widgets.
- Create or edit a Layer.
- Add an Any condition group.
- Inside the group, add a Homepage condition and a Role condition set to
Administrator.
Creating Custom Conditions
Implement custom layer conditions by following the Rules module pattern. Refer to the OrchardCore.Rules module for guidance on creating custom condition evaluators.
JavaScript Conditions
The Javascript condition allows writing custom rule logic in JavaScript. Use the scripting API provided by OrchardCore.Scripting:
// Example: Show widget only on URLs starting with /blog
url().startsWith('/blog')
Widget Management Workflow
- Enable
OrchardCore.LayersandOrchardCore.Widgetsfeatures. - Configure zones in Design > Settings > Zones.
- Create layers with appropriate conditions in Design > Widgets.
- Create widget content types with the
Widgetstereotype. - Add widgets to zones and associate them with layers.
- Widgets display only when their associated layer's conditions evaluate to
true.