Orchardcore resources

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore resources is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for managing CSS and JavaScript resources in Orchard Core. Covers resource manifest registration, built-in named resources (jQuery, bootstrap, bootstrap-select, font-awesome, vuejs 3, vue-multiselect, vue-draggable, Sortable, codemirror, monaco, list-management), CDN settings, the OrchardCore

How to use this skill

Skill file

Orchard Core Resources - Prompt Templates

Managing CSS and JavaScript Resources

You are an Orchard Core expert. Generate code and configuration for registering and rendering CSS/JavaScript resources in Orchard Core.

Guidelines

Resource Settings (Admin Settings)

| Setting | Description |

|-------------------|----------------------------------------------------------------------------------------------|

| AppendVersion | Appends a version hash to local scripts/styles for cache busting. On by default. |

| UseCdn | Serves scripts/styles from configured CDN URLs instead of local files. Off by default. |

| ResourceDebugMode | Serves non-minified versions and disables CDN/CdnBaseUrl. For development use. |

| CdnBaseUrl | Prepends this base URL to local resources served via the Resource Manager. |

Built-in Named Resources

Common resources provided by OrchardCore.Resources (latest versions; older versions of several remain registered, so version="4" or depends-on="bootstrap:4" still resolve):

| Name | Type | Version | Dependencies |

|------|------|---------|--------------|

| jQuery / jQuery.slim | Script | 3.7.1 | - |

| jQuery-ui | Script, Style | 1.14.2 | jQuery |

| jQuery-ui-i18n | Script | 1.14.2 | jQuery-ui |

| popperjs | Script | 2.11.8 | - |

| bootstrap | Script | 5.3.8 (also 4.6.1) | popperjs |

| bootstrap / bootstrap-rtl | Style | 5.3.8 | - |

| bootstrap-select | Script, Style | 1.2.6 | bootstrap |

| font-awesome | Style, Script | 7.3.1 (also 6.x, 5.x) | - |

| font-awesome-v4-shims | Script | 7.3.1 | - |

| codemirror (+ codemirror-mode-*, codemirror-addon-*) | Script, Style | 5.65.7 | - |

| monaco | Script, Style | 0.52.2 | - (ES module build, no monaco-loader) |

| trumbowyg | Script, Style | 2.31.0 | jquery-resizable |

| nouislider | Script, Style | 15.7.0 | - |

| vuejs | Script | 3.5.13 | - |

| vue-multiselect | Script, Style | 3.2.0 | vuejs |

| Sortable | Script | 1.15.3 | - |

| vue-draggable | Script | 4.1.0 | vuejs, Sortable |

| js-cookie | Script | 3.0.5 | - |

| list-management | Script | 1.0.0 | - |

list-management is a reusable admin helper for searchable lists, bulk selection, and filter auto-submit. Require it with <script asp-name="list-management" at="Foot"></script> and opt a container in with data-list-management.

Registering a Resource Manifest

Create a configuration class to define named resources:

namespace MyModule;

public sealed class ResourceManagementOptionsConfiguration : IConfigureOptions<ResourceManagementOptions>
{
    private static readonly ResourceManifest _manifest;

    static ResourceManagementOptionsConfiguration()
    {
        _manifest = new ResourceManifest();

        _manifest
            .DefineScript("MyModule-CustomScript")
            .SetUrl("~/MyModule/js/custom.min.js", "~/MyModule/js/custom.js")
            .SetCdn(
                "https://cdn.example.com/custom.min.js",
                "https://cdn.example.com/custom.js")
            .SetCdnIntegrity(
                "sha384-abc123minifiedhash",
                "sha384-abc123debughash")
            .SetVersion("1.0.0")
            .SetDependencies("bootstrap:5");

        _manifest
            .DefineStyle("MyModule-CustomStyle")
            .SetUrl("~/MyModule/css/custom.min.css", "~/MyModule/css/custom.css")
            .SetVersion("1.0.0")
            .SetDependencies("bootstrap");
    }

    public void Configure(ResourceManagementOptions options)
    {
        options.ResourceManifests.Add(_manifest);
    }
}

Register in Startup.cs:

namespace MyModule;

public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddResourceConfiguration<ResourceManagementOptionsConfiguration>();
    }
}

Configuration (appsettings.json)

The resource settings can also be provided from configuration, globally or per tenant (OrchardCore:{TenantName}:Resources). The site General settings override these values.

{
  "OrchardCore": {
    "Resources": {
      "ResourceDebugMode": "FromConfiguration",
      "UseCdn": false,
      "CdnBaseUrl": "https://cdn.example.com",
      "AppendVersion": true
    }
  }
}

ResourceDebugMode accepts FromConfiguration (debug in every environment except Production), Enabled, or Disabled. The former OrchardCore_Resources section name still works but is deprecated.

Using Tag Helpers (Razor)

Add to _ViewImports.cshtml:

@addTagHelper *, OrchardCore.ResourceManagement
Register a Named Resource
<script asp-name="bootstrap"></script>
<style asp-name="bootstrap"></style>
Force CDN Usage
<script asp-name="bootstrap" use-cdn="true"></script>
Specify Version
<script asp-name="bootstrap" version="4"></script>
Append Version Hash
<script asp-name="bootstrap" asp-append-version="true"></script>
Specify Location (Head or Foot)
<script asp-name="bootstrap" at="Foot"></script>
Inline Resource Definition

Define and register a resource directly in a view:

<script asp-name="foo" asp-src="~/MyTheme/js/foo.min.js" debug-src="~/MyTheme/js/foo.js" depends-on="bootstrap:5" version="1.0"></script>
<script asp-name="bar" asp-src="~/MyTheme/js/bar.min.js" debug-src="~/MyTheme/js/bar.js" depends-on="foo:1.0" version="1.0"></script>

Using Liquid Tags

Register a Named Resource
{% script name:"bootstrap" %}
{% style name:"bootstrap" %}
Force CDN
{% script name:"bootstrap", use_cdn:"true" %}
Specify Version
{% script name:"bootstrap", version:"4" %}
Append Version Hash
{% script name:"bootstrap", append_version:"true" %}
Specify Location
{% script name:"bootstrap", at:"Foot" %}
Inline Resource Definition
{% script name:"foo", src:"~/MyTheme/js/foo.min.js", debug_src:"~/MyTheme/js/foo.js", depends_on:"bootstrap:5", version:"1.0" %}

Custom Inline Scripts

Razor
<script at="Foot">
    document.addEventListener('DOMContentLoaded', function() {
        console.log('Page loaded');
    });
</script>

Named inline script (rendered only once, with dependencies). A script that uses jQuery must declare it, because nothing else on the page is guaranteed to require it:

<script asp-name="MyInitScript" at="Foot" depends-on="jQuery">
    $(function() { /* initialization */ });
</script>
Liquid
{% scriptblock at: "Foot" %}
    document.addEventListener('DOMContentLoaded', function() {
        console.log('Page loaded');
    });
{% endscriptblock %}

Named inline script:

{% scriptblock name: "MyInitScript", at: "Foot", depends_on:"jQuery" %}
    $(function() { /* initialization */ });
{% endscriptblock %}

Custom Inline Styles

Razor
<style at="Head">
    .hero-section { background: linear-gradient(to right, #667eea, #764ba2); }
</style>

Named inline style (rendered only once):

<style asp-name="hero-style" depends-on="bootstrap">
    .hero-section { background: linear-gradient(to right, #667eea, #764ba2); }
</style>
Liquid
{% styleblock at: "Head" %}
    .hero-section { background: linear-gradient(to right, #667eea, #764ba2); }
{% endstyleblock %}

Named inline style:

{% styleblock name: "hero-style", depends_on:"bootstrap" %}
    .hero-section { background: linear-gradient(to right, #667eea, #764ba2); }
{% endstyleblock %}

Link Tag Helper

Use the link tag for non-stylesheet relationships (favicons, preloads):

Razor
<link asp-src="~/MyTheme/favicon/favicon-16x16.png" rel="icon" type="image/png" sizes="16x16" />
Liquid
{% link rel:"icon", type:"image/png", sizes:"16x16", src:"~/MyTheme/favicon/favicon-16x16.png" %}

Meta Tags

Razor
<meta asp-name="description" content="My website description" />
Liquid
{% meta name:"description", content:"My website description" %}

Meta tag properties:

| Property | Description |

|------------------------------|--------------------------------------|

| name (asp-name in Razor) | The name attribute |

| content | The content attribute |

| httpequiv | The http-equiv attribute |

| charset | The charset attribute |

| separator | Separator for multiple same-name tags|

Rendering Resources in Layout

Resources must be rendered in the layout to appear on the page.

Head Resources (in `<head>`)

Razor:

<head>
    <resources type="Meta" />
    <resources type="HeadLink" />
    <resources type="HeadScript" />
    <resources type="Stylesheet" />
</head>

Liquid:

<head>
    {% resources type: "Meta" %}
    {% resources type: "HeadLink" %}
    {% resources type: "HeadScript" %}
    {% resources type: "Stylesheet" %}
</head>

<resources type="Header" /> (Liquid {% resources type: "Header" %}) renders Meta, HeadLink, Stylesheet, and HeadScript in one call. Render shapes that register resources (menus, navbars) before the head resources, or pre-render them into a variable at the top of the layout.

Foot Resources (at end of `<body>`)

Razor:

<body>
    ...
    <resources type="FootScript" />
</body>

Liquid:

<body>
    ...
    {% resources type: "FootScript" %}
</body>

Using the IResourceManager API

Inject IResourceManager (package OrchardCore.ResourceManagement.Abstractions) to register resources from code that runs during the request, such as an MVC filter, a display driver, or a view component. Never register resources from an IShapeTableProvider: the shape table is built once and cached.

using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Filters;
using OrchardCore.Admin;
using OrchardCore.ResourceManagement;

namespace MyModule;

public sealed class AdminAssetsFilter : IAsyncResultFilter
{
    private readonly IResourceManager _resourceManager;

    public AdminAssetsFilter(IResourceManager resourceManager)
    {
        _resourceManager = resourceManager;
    }

    public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
    {
        if (context.IsViewOrPageResult() && AdminAttribute.IsApplied(context.HttpContext))
        {
            // Register named resources.
            _resourceManager.RegisterResource("stylesheet", "bootstrap-select").AtHead();
            _resourceManager.RegisterResource("script", "bootstrap-select").AtFoot();

            // Register a custom inline script.
            _resourceManager.RegisterFootScript(
                new HtmlString("<script>console.log('Hello');</script>"));

            // Register a meta tag.
            _resourceManager.RegisterMeta(
                new MetaEntry { Content = "Orchard Core", Name = "generator" });
        }

        await next();
    }
}

Register the filter with services.Configure<MvcOptions>(options => options.Filters.Add<AdminAssetsFilter>());.

RequireSettings also supports UseVersion("5") (latest matching version, exception when missing), ShouldAppendVersion(true), UseCdn(true), UseCulture(...), and SetDependencies(...). Missing named resources are logged as errors.

Resource Location Convention

| Location | Description |

|-----------|-------------------------------------------------------------------|

| Head | Rendered in <head> via HeadScript resources tag |

| Foot | Rendered at end of <body> via FootScript resources tag |

| Inline | Rendered at the point of declaration (default for unnamed scripts)|

Upgrading from 3.x

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.