Orchardcore layers

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore layers is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for configuring layers in Orchard Core. Covers layer creation, layer rules and conditions, zone-based widget visibility, the Layers and LayerSettings recipe steps, JavaScript condition methods, validation, isolation and cancellation, URL rule expressions, the ManageLayers permission, and condi

How to use this skill

Skill file

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

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 Settings > Zones in the admin. Common zone names include:

Recipe: Zones

{
  "steps": [
    {
      "name": "Settings",
      "LayerSettings": {
        "Zones": [ "Header", "Content", "Footer" ]
      }
    }
  ]
}

Recipe: Creating Layers

Name must match the registered condition factory name (the condition class

name). Conditions nested inside an All/Any group also need $type

(for example "OrchardCore.Rules.Models.UrlCondition, OrchardCore.Rules"),

which the All Layers deployment step emits. Supplying LayerRule for an

existing layer replaces its whole condition list, and an unknown condition name

fails the step without saving.

{
  "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": {
            "Layer": "Always",
            "Zone": "Footer",
            "Position": 10
          },
          "HtmlBodyPart": {
            "Html": "<p>&copy; 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:

  1. Navigate to Design > Widgets.
  2. Create or edit a Layer.
  3. Add an All condition group.
  4. 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:

  1. Navigate to Design > Widgets.
  2. Create or edit a Layer.
  3. Add an Any condition group.
  4. 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 evaluates an expression that must convert to a

Boolean. Layers adds these global methods:

| Function | Behavior |

|---|---|

| isHomepage() | The request path is the tenant home page. |

| isAnonymous() / isAuthenticated() | Authentication state of the current user. |

| isInRole(role) | Role name, case-insensitive. |

| url(pattern) | Case-insensitive path match; a trailing * makes it a prefix match. |

| culture(name) | Current culture or its parent culture, case-insensitive. |

// Show widgets on the blog section for signed-in users.
isAuthenticated() && url("/blog*")

runtime exceptions, and non-Boolean results are reported as validation

messages instead of failing the request.

const declarations from one layer's condition are not visible to another,

so write each condition as a self-contained expression.

running when the client disconnects is stopped with an

OperationCanceledException. Configure time or statement limits through

IOptions<Jint.Options> (see orchardcore-scripting).

over JavaScript when they express the rule; they are faster and easier to

audit.

Widget Management Workflow

  1. Enable OrchardCore.Layers and OrchardCore.Widgets features.
  2. Configure zones in Settings > Zones.
  3. Create layers with appropriate conditions in Design > Widgets.
  4. Create widget content types with the Widget stereotype.
  5. Add widgets to zones and associate them with layers.
  6. Widgets display only when their associated layer's conditions evaluate to true.

Upgrading from 3.x

so a var or const declared in one could break another. Each condition is

now isolated; remove any reliance on values declared by another layer.

instead of an unhandled exception.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.