Orchardcore widgets

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore widgets is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for creating and managing widgets in Orchard Core. Covers widget content types, zones, layers, layer rules, widget placement configuration, Widget shape templates and wrappers, safe rendering of widget HTML, and ManageLiquidTemplates for Liquid widgets. Use this skill when requests mention Orc

How to use this skill

Skill file

Orchard Core Widgets - Prompt Templates

Create and Manage Widgets

You are an Orchard Core expert. Generate widget definitions, layer configurations, and zone placement for Orchard Core.

Guidelines

Enabling Widget Features

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Widgets",
        "OrchardCore.Layers",
        "OrchardCore.Flows"
      ],
      "disable": []
    }
  ]
}

Creating a Widget Content Type

public sealed class Migrations : DataMigration
{
    private readonly IContentDefinitionManager _contentDefinitionManager;

    public Migrations(IContentDefinitionManager contentDefinitionManager)
    {
        _contentDefinitionManager = contentDefinitionManager;
    }

    public async Task<int> CreateAsync()
    {
        await _contentDefinitionManager.AlterTypeDefinitionAsync("{{WidgetName}}", type => type
            .DisplayedAs("{{WidgetDisplayName}}")
            .Stereotype("Widget")
            .WithPart("{{WidgetName}}", part => part
                .WithPosition("0")
            )
        );

        await _contentDefinitionManager.AlterPartDefinitionAsync("{{WidgetName}}", part => part
            .WithField("{{FieldName}}", field => field
                .OfType("{{FieldType}}")
                .WithDisplayName("{{FieldDisplayName}}")
                .WithPosition("0")
            )
        );

        return 1;
    }
}

Layer Configuration via Recipe

{
  "steps": [
    {
      "name": "Layers",
      "Layers": [
        {
          "Name": "Always",
          "LayerRule": {
            "Conditions": [
              {
                "Name": "BooleanCondition",
                "Value": true
              }
            ]
          },
          "Description": "Widgets on this layer are always displayed."
        },
        {
          "Name": "Homepage",
          "LayerRule": {
            "Conditions": [
              {
                "Name": "HomepageCondition",
                "Value": true
              }
            ]
          },
          "Description": "Widgets on this layer are displayed on the homepage."
        },
        {
          "Name": "Authenticated",
          "LayerRule": {
            "Conditions": [
              {
                "Name": "IsAuthenticatedCondition",
                "Value": true
              }
            ]
          },
          "Description": "Widgets on this layer are displayed for authenticated users."
        }
      ]
    }
  ]
}

Layer Rule Expressions

Common layer rule conditions:

Placing Widgets in Zones

Widgets are assigned to zones and layers via the admin UI or recipes:

{
  "steps": [
    {
      "name": "Content",
      "data": [
        {
          "ContentItemId": "widget-hero-banner",
          "ContentType": "HeroBanner",
          "DisplayText": "Welcome Banner",
          "Latest": true,
          "Published": true,
          "LayerMetadata": {
            "Layer": "Homepage",
            "Zone": "Header",
            "Position": 0
          },
          "HeroBanner": {
            "Heading": {
              "Text": "Welcome to Our Site"
            },
            "Description": {
              "Html": "<p>Your one-stop solution.</p>"
            }
          }
        }
      ]
    }
  ]
}

Widget Template (Liquid)

The Widget shape exposes Model.ContentItem, the Model.Content zone with

the shapes of its parts and fields, and Model.Header, Model.Meta,

Model.Footer, Model.Classes. Create Views/Widget-{{WidgetName}}.liquid

(Widget__{{WidgetName}}):

<div class="{{ Model.Classes | join: " " }}">
    <h3>{{ Model.ContentItem.Content.{{WidgetName}}.Heading.Text }}</h3>
    <div class="widget-body">
        {{ Model.Content["{{WidgetName}}-Body"] | shape_render }}
    </div>
</div>

Rendering the {PartName}-{FieldName} field shape processes shortcodes and

sanitizes the HTML. The built-in themes render Paragraph and RawHtml the

same way ({{ Model.Content.Paragraph-Content | shape_render }}).

Widget Template (Razor)

Create a template at Views/Widget-{{WidgetName}}.cshtml:

<div class="@string.Join(" ", Model.Classes)">
    <h3>@Model.ContentItem.Content.{{WidgetName}}.Heading.Text</h3>
    <div class="widget-body">
        @await DisplayAsync(Model.Content.Named("{{WidgetName}}-Body"))
    </div>
</div>

Widget Wrapper

Widgets rendered by Layers are wrapped by Widget_Wrapper

(Widget.Wrapper.cshtml) that adds the title container. Override it, or the

Widget-{{WidgetName}}.Wrapper / Widget-Zone-Footer.Wrapper alternates, to

remove the wrapper markup:

{{ Model.Content | shape_render }}

FlowPart for Inline Widgets

Allow widgets inside content items using FlowPart:

await _contentDefinitionManager.AlterTypeDefinitionAsync("Page", type => type
    .WithPart("FlowPart")
);

FlowPart allows editors to add widgets inline within content item editing.

WidgetsListPart Editor Placement

To hide or move the whole WidgetsListPart editor row in the admin UI:

{
  "ContentPart_Edit": [
    {
      "differentiator": "PlacementTest-WidgetsListPart",
      "place": "-"
    }
  ]
}

If the part is attached as a named part, replace WidgetsListPart with the part name.

Widgets in the Admin Zones

On Design → Widgets, each widget in a zone renders as Widget.SummaryAdmin. Since 4.0 that template renders its Actions and ActionsMenu zones through @await DisplayAsync(await Factory.CreateAdminListActionsAsync((IShape)Model)), so the widget's buttons follow Settings → Admin → Actions layout (Buttons, or one ellipsis Menu) like admin list rows. An override of Widget.SummaryAdmin.cshtml must render the actions the same way instead of a hand-written btn-group with an "Actions" dropdown, and place extra buttons as shapes in Actions/ActionsMenu (see orchardcore-admin-lists).

Built-in Widget Content Types

The default recipes (Blog, Agency) create widget types such as:

Widget Best Practices

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.