Przejdź do treści
Biblioteka skilli
Marketing i treści · Budowanie i kod

orchardcore-shortcodes

/orchardcore-shortcodes

Tworzy shortcody Orchard Core, czyli szablony wstawiane do treści, oraz dostawców kodowych z wbudowanymi obrazami i lokalizacją.

Licencja
MIT
Ostatnia zmiana repozytorium
21.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 21.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Tworzy shortcody Orchard Core, czyli szablony wstawiane do treści, oraz dostawców kodowych z wbudowanymi obrazami i lokalizacją.

Oryginalny opis (EN)

Skill for creating and using shortcodes in Orchard Core. Covers shortcode template creation via admin UI, the ShortcodeTemplates recipe step and deployment step, the ManageShortcodeTemplates permission, code-based shortcode providers using delegate and class patterns, built-in shortcodes (image, asset_url, locale), and shortcode rendering before final HTML sanitization in HTML and Markdown parts and fields. Use this skill when requests mention Orchard Core Shortcodes, Create and Use Shortcodes, Enabling Shortcodes, Shortcode Templates (Admin UI), Template Arguments, Example [display_text] Temp

Jak działa

  1. Create and Use Shortcodes
Sekcje z nagłówków SKILL.md, w oryginale · 266 linii, 1 101 słów
Podgląd SKILL.md
---
name: orchardcore-shortcodes
description: Skill for creating and using shortcodes in Orchard Core. Covers shortcode template creation via admin UI, the ShortcodeTemplates recipe step and deployment step, the ManageShortcodeTemplates permission, code-based shortcode providers using delegate and class patterns, built-in shortcodes (image, asset_url, locale), and shortcode rendering before final HTML sanitization in HTML and Markdown parts and fields. Use this skill when requests mention Orchard Core Shortcodes, Create and Use Shortcodes, Enabling Shortcodes, Shortcode Templates (Admin UI), Template Arguments, Example [display_text] Template or closely related Orchard Core work. Strong matches include work with OrchardCore.Shortcodes, OrchardCore.Shortcodes.Templates, OrchardCore.Localization, IShortcodeProvider, HtmlBodyPart, HtmlField, MarkdownBodyPart, MarkdownField, IServiceCollection, AlertShortcodeProvider.
license: Apache-2.0
metadata:
  author: CrestApps Team
  version: "1.0"
---

# Orchard Core Shortcodes - Prompt Templates

## Create and Use Shortcodes

You are an Orchard Core expert. Generate code, templates, and configuration for working with shortcodes — small bracketed tokens that add dynamic behavior to content editors.

### Guidelines

- Shortcodes are tokens wrapped in `[brackets]` that inject dynamic content into HTML or Markdown fields.
- Enable the `OrchardCore.Shortcodes` feature to use shortcodes; enable `OrchardCore.Shortcodes.Templates` for admin-managed templates.
- Shortcode templates created in the admin UI (_Design → Shortcodes_) use Liquid syntax.
- Admin-created shortcode templates can override code-based shortcodes with the same name.
- Managing shortcode templates requires `OrchardCore.Shortcodes.ShortcodesPermissions.ManageShortcodeTemplates` (the old `OrchardCore.Shortcodes.Permissions.ManageShortcodeTemplates` member was removed in 4.0).
- Code-based shortcodes are registered using `ShortcodeDelegate` (inline lambda) or `IShortcodeProvider` (class-based).
- Built-in shortcodes include `[image]`, `[asset_url]`, and `[locale]`.
- Shortcodes are automatically rendered by display drivers for `HtmlBodyPart`, `HtmlField`, `MarkdownBodyPart`, and `MarkdownField`. Shortcodes run on the rendered HTML (after Markdown conversion) and before final-output sanitization, so markup a shortcode returns is sanitized when the part or field has `SanitizeHtml` enabled.
- For manual rendering, use the `shortcode` Liquid filter or `Orchard.ShortcodesToHtmlAsync()` Razor helper.
- All C# classes must use the `sealed` modifier.
- All recipe JSON must be wrapped in the root `{ "steps": [...] }` format.

### Enabling Shortcodes

```json
{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Shortcodes",
        "OrchardCore.Shortcodes.Templates"
      ],
      "disable": []
    }
  ]
}
```

### Shortcode Templates (Admin UI)

Shortcode templates are managed via _Design → Shortcodes_ in the admin dashboard. Each template has the following fields:

| Parameter          | Description                                                                  |
|--------------------|------------------------------------------------------------------------------|
| `Name`             | The shortcode name, without brackets.                                        |
| `Hint`             | Tooltip text displayed in the shortcode picker.                              |
| `Usage`            | HTML string describing usage and arguments.                                  |
| `Categories`       | Categories the shortcode belongs to.                                         |
| `Return Shortcode` | The shortcode value returned from the picker when selected. Defaults to Name.|
| `Content`          | The Liquid template that renders the shortcode output.                       |

### Template Arguments

The following variables are available inside a shortcode Liquid template:

| Variable  | Description                                                              |
|-----------|--------------------------------------------------------------------------|
| `Args`    | Named arguments provided by the user (e.g., `[shortcode key="value"]`). |
| `Content` | Inner content between opening and closing tags.                          |
| `Context` | Contextual data from the caller (e.g., the parent `ContentItem`).        |

### Example: `[display_text]` Template

| Field     | Value                                   |
|-----------|-----------------------------------------|
| `Name`    | `display_text`                          |
| `Hint`    | Returns the display text of the content item. |
| `Usage`   | `[display_text]`                        |
| `Content` | `{{ Context.ContentItem.DisplayText }}` |

> The `ContentItem` context is only available when the caller (e.g., `HtmlBodyPart`) passes the `ContentItem` to the shortcode context.

### Example: `[site_name]` Template

| Field     | Value                  |
|-----------|------------------------|
| `Name`    | `site_name`            |
| `Hint`    | Returns the site name. |
| `Usage`   | `[site_name]`          |
| `Content` | `{{ Site.SiteName }}`  |

### Example: `[primary]` Template with Arguments

| Field     | Value |
|-----------|-------|
| `Name`    | `primary` |
| `Hint`    | Formats text in the theme's primary color. |
| `Usage`   | `[primary text]` or `[primary]text[/primary]` |
| `Content` | See Liquid below |

```liquid
{% capture output %}
{% if Args.Text != nil %}
<span class="text-primary">{{ Args.Text }}</span>
{% else %}
<span class="text-primary">{{ Content }}</span>
{% endif %}
{% endcapture %}
{{ output | sanitize_html | raw }}
```

### Shortcode Templates via Recipe

The `ShortcodeTemplates` step creates or updates templates by name. `Usage` is
sanitized on import; `DefaultValue` is the **Return Shortcode** value.

```json
{
  "steps": [
    {
      "name": "ShortcodeTemplates",
      "ShortcodeTemplates": {
        "site_name": {
          "Content": "{{ Site.SiteName }}",
          "Hint": "Returns the site name.",
          "Usage": "[site_name]",
          "DefaultValue": "[site_name]",
          "Categories": [ "Site" ]
        }
      }
    }
  ]
}
```

The **All Shortcode Templates** deployment step (`AllShortcodeTemplates`)
exports every template in the same format.

### Registering a Shortcode via Delegate

Use `ShortcodeDelegate` for simple inline shortcodes registered in `Startup.ConfigureServices`:

```csharp
public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddShortcode("bold", (args, content, ctx) =>
        {
            var text = args.NamedOrDefault("text");

            if (!string.IsNullOrEmpty(text))
            {
                content = text;
            }

            return ValueTask.FromResult($"<b>{content}</b>");
        }, describe =>
        {
            describe.DefaultValue = "[bold text-here]";
            describe.Hint = "Add bold formatting with a shortcode.";
            describe.Usage = "[bold 'your bold content here']";
            describe.Categories = ["HTML Content"];
        });
    }
}
```

### Registering a Shortcode via IShortcodeProvider

For complex shortcodes, implement `IShortcodeProvider` and register with `AddShortcode<T>`:

```csharp
public sealed class AlertShortcodeProvider : IShortcodeProvider
{
    public ValueTask<string> EvaluateAsync(string identifier, Arguments args, string content, Context context)
    {
        var alertType = args.NamedOrDefault("type") ?? "info";

        return ValueTask.FromResult(
            $"<div class=\"alert alert-{alertType}\" role=\"alert\">{content}</div>"
        );
    }
}
```

Register in `Startup.ConfigureServices`:

```csharp
public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.AddShortcode<AlertShortcodeProvider>("alert", describe =>
        {
            describe.DefaultValue = "[alert] [/alert]";
            describe.Hint = "Display a Bootstrap alert box.";
            describe.Usage =
                "[alert type=\"info\"]Your message here[/alert]<br>" +
                "Supported types: info, warning, danger, success";
            describe.Categories = ["HTML Content", "UI Components"];
        });
    }
}
```

### Built-In Shortcode: `[image]`

Renders an image from the media library.

```
[image alt="My lovely image"]my-image.jpg[/image]
```

| Parameter        | Description                                                        |
|------------------|--------------------------------------------------------------------|
| `alt`            | Alternative text for the image (accessibility and SEO).            |
| `class`          | CSS class attribute for the `<img>` tag.                           |
| `append_version` | Set to `true` to add a cache-busting query string.                 |
| `format`         | Output format: `jpeg`, `png`, `gif`, or `bmp`.                    |
| `quality`        | JPEG quality (0–100, default 75).                                  |
| `width`, `height`| Resize dimensions. Allowed: 16, 32, 50, 100, 160, 240, 480, 600, 1024, 2048. |
| `mode`           | Resize mode: `pad`, `boxpad`, `max` (default), `min`, `stretch`, `crop`. |

### Built-In Shortcode: `[asset_url]`

Returns a relative URL from the media library. Useful for backgrounds or links.

```
[asset_url]my-image.jpg[/asset_url]
```

Returns a path like `/my-tenant/media/my-image.jpg`. Supports the same `format`, `quality`, `width`, `height`, and `mode` parameters as `[image]`.

### Built-In Shortcode: `[locale]`

Conditionally renders content based on the current culture. Requires `OrchardCore.Localization`.

```
[locale en]English Text[/locale][locale fr]French Text[/locale]
```

By default, parent cultures match (e.g., `en-CA` matches `[locale en]`). Pass `false` as the second argument for exact matching:

```
[locale en false]Exact English only[/locale]
```

### Rendering Shortcodes in Templates

Shortcodes are automatically rendered for `HtmlBodyPart`, `HtmlField`, `MarkdownBodyPart`, and `MarkdownField` shapes. Prefer rendering the shape, which also applies sanitization:

```liquid
{{ Model.Content.HtmlBodyPart | shape_render }}
```

For manual rendering of a raw string, sanitize the result unless the source is trusted, because stored HTML is no longer sanitized on save:

#### Liquid

```liquid
{{ Model.ContentItem.Content.RawHtml.Content.Html | shortcode | sanitize_html | raw }}
```

#### Razor

`ShortcodesToHtmlAsync(html, model)` returns an `HtmlString`; pass the shape
`Model` to make its `ContentItem` available to the shortcodes:

```cshtml
@{
    var html = (await Orchard.ShortcodesToHtmlAsync((string)Model.ContentItem.Content.RawHtml.Content.Html, Model)).ToString();
}
@Orchard.SanitizeHtml(html)
```

Wersje

W bazie nie ma innych skilli o nazwie orchardcore-shortcodes.

Identyczna treść występuje jeszcze w 1 innych folderach na GitHubie. Tu pokazujemy jedną, najlepiej ocenioną kopię.

Migawka bazy z 13.11.2026 · wersja paczki 0b10e44032b5 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 2 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100orchardcore-markdown
    Opisuje użycie MarkdownBodyPart i MarkdownField w Orchard Core: edycję Markdown, szablony Liquid i Razor, sanityzację wyniku, shortcody i potok rozszerzeń Markdig.
  • 100orchardcore-html
    Opisuje użycie HtmlBodyPart w Orchard Core: edycję treści HTML, szablony Liquid i Razor, sanityzację HTML, shortcody oraz edytory Wysiwyg, Trumbowyg i Monaco.
  • 100shortcode-block-security
    Zabezpiecza shortcodes i bloki WordPress: normalizuje atrybuty, sprawdza je z listami dozwolonych wartości i escapuje wynik, zapobiegając XSS.
  • 100orchardcore-video-producer
    Produkuje wideo z narracją o Orchard Core w jednolitej specyfikacji: 1080p, logo, napisy, ten sam głos syntetyczny i plik poniżej 10 MB.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.