--- name: orchardcore-resources description: Skill for managing CSS and JavaScript resources in Orchard Core. Covers resource manifest registration, named resources, CDN configuration, script and style tag helpers, resource dependencies, inline scripts, resource versioning, and module asset conventions. Use this skill when requests mention Orchard Core Resources, Managing CSS and JavaScript Resources, Resource Settings (Admin Configuration), Built-in Named Resources, Registering a Resource Manifest, Using Tag Helpers (Razor), or closely related Orchard Core implementation, setup, extension, or troubleshooting work. Strong matches include work with OrchardCore.Resources, OrchardCore.ResourceManagement, IConfigureOptions, IServiceCollection, IResourceManager, MyShapeTableProvider, IShapeTableProvider, ShapeTableBuilder. It also helps with Registering a Resource Manifest, Using Tag Helpers (Razor), Using Liquid Tags, plus the code patterns, admin flows, recipe steps, and referenced examples captured in this skill. --- # 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 - The `OrchardCore.Resources` module provides the Resource Manager for declaring, ordering, and rendering scripts and styles. - Resources are served from a module or theme's `wwwroot` folder via `StaticFileMiddleware`. - Resource paths use the `~/ModuleName/` or `~/ThemeName/` prefix convention (tilde represents tenant base path). - Named resources have a name, type (script/stylesheet), optional version, CDN URLs, and dependencies. - Register resource manifests by implementing `IConfigureOptions` and calling `services.AddResourceConfiguration()` in `Startup`. - Use tag helpers (` ``` #### Force CDN Usage ```html ``` #### Specify Version ```html ``` #### Append Version Hash ```html ``` #### Specify Location (Head or Foot) ```html ``` #### Inline Resource Definition Define and register a resource directly in a view: ```html ``` ### Using Liquid Tags #### Register a Named Resource ```liquid {% script name:"bootstrap" %} {% style name:"bootstrap" %} ``` #### Force CDN ```liquid {% script name:"bootstrap", use_cdn:"true" %} ``` #### Specify Version ```liquid {% script name:"bootstrap", version:"4" %} ``` #### Append Version Hash ```liquid {% script name:"bootstrap", append_version:"true" %} ``` #### Specify Location ```liquid {% script name:"bootstrap", at:"Foot" %} ``` #### Inline Resource Definition ```liquid {% script name:"foo", src:"~/MyTheme/js/foo.min.js", debug_src:"~/MyTheme/js/foo.js", depends_on:"jQuery", version:"1.0" %} ``` ### Custom Inline Scripts #### Razor ```html ``` Named inline script (rendered only once, with dependencies): ```html ``` #### Liquid ```liquid {% scriptblock at: "Foot" %} document.addEventListener('DOMContentLoaded', function() { console.log('Page loaded'); }); {% endscriptblock %} ``` Named inline script: ```liquid {% scriptblock name: "MyInitScript", at: "Foot", depends_on:"jQuery" %} $(function() { /* initialization */ }); {% endscriptblock %} ``` ### Custom Inline Styles #### Razor ```html ``` Named inline style (rendered only once): ```html ``` #### Liquid ```liquid {% styleblock at: "Head" %} .hero-section { background: linear-gradient(to right, #667eea, #764ba2); } {% endstyleblock %} ``` Named inline style: ```liquid {% 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 ```html ``` #### Liquid ```liquid {% link rel:"icon", type:"image/png", sizes:"16x16", src:"~/MyTheme/favicon/favicon-16x16.png" %} ``` ### Meta Tags #### Razor ```html ``` #### Liquid ```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 ``) **Razor:** ```html ``` **Liquid:** ```liquid {% resources type: "Meta" %} {% resources type: "HeadLink" %} {% resources type: "HeadScript" %} {% resources type: "Stylesheet" %} ``` #### Foot Resources (at end of ``) **Razor:** ```html ... ``` **Liquid:** ```liquid ... {% resources type: "FootScript" %} ``` ### Using the IResourceManager API Inject `IResourceManager` for programmatic resource registration from code: ```csharp namespace MyModule; public sealed class MyShapeTableProvider : IShapeTableProvider { private readonly IResourceManager _resourceManager; public MyShapeTableProvider(IResourceManager resourceManager) { _resourceManager = resourceManager; } public ValueTask DiscoverAsync(ShapeTableBuilder builder) { // Register a named resource var settings = _resourceManager.RegisterResource("script", "bootstrap"); settings.AtFoot(); settings.UseVersion("5"); // Register a custom inline script _resourceManager.RegisterFootScript( new HtmlString("")); // Register a meta tag _resourceManager.RegisterMeta( new MetaEntry { Content = "Orchard Core", Name = "generator" }); return ValueTask.CompletedTask; } } ``` ### Resource Location Convention | Location | Description | |-----------|-------------------------------------------------------------------| | `Head` | Rendered in `` via `HeadScript` resources tag | | `Foot` | Rendered at end of `` via `FootScript` resources tag | | `Inline` | Rendered at the point of declaration (default for unnamed scripts)|