Orchardcore lists

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore lists is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for working with ListPart in Orchard Core. Covers list content types, ListPart shapes, list item rendering, PagerSlim cursor paging and the full pager, page size selection with the pageSize query string, ShowHeader, admin list ordering with List or Grid layouts, ContainedPartIndex queries, ICo

How to use this skill

Skill file

Orchard Core Lists - Prompt Templates

Working with ListPart

You are an Orchard Core expert. Generate code and configuration for list-based content types using ListPart in Orchard Core.

Guidelines

Enabling List Features

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Lists"
      ],
      "disable": []
    }
  ]
}

Creating a Blog with ListPart

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

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

    public async Task<int> CreateAsync()
    {
        await _contentDefinitionManager.AlterTypeDefinitionAsync("Blog", type => type
            .Creatable()
            .Listable()
            .WithPart("TitlePart", part => part.WithPosition("0"))
            .WithPart("AutoroutePart", part => part
                .WithPosition("1")
                .WithSettings(new AutoroutePartSettings
                {
                    Pattern = "{{ Model.ContentItem | display_text | slugify }}",
                })
            )
            .WithPart("ListPart", part => part
                .WithPosition("2")
                .WithSettings(new ListPartSettings
                {
                    PageSize = 10,
                    EnableOrdering = true,
                    ContainedContentTypes = ["BlogPost"],
                })
            )
        );

        await _contentDefinitionManager.AlterTypeDefinitionAsync("BlogPost", type => type
            .Draftable()
            .Versionable()
            .WithPart("TitlePart", part => part.WithPosition("0"))
            .WithPart("AutoroutePart", part => part
                .WithPosition("1")
                .WithSettings(new AutoroutePartSettings
                {
                    Pattern = "{{ Model.ContentItem | container | display_text | slugify }}/{{ Model.ContentItem | display_text | slugify }}",
                })
            )
            .WithPart("HtmlBodyPart", part => part
                .WithPosition("2")
                .WithEditor("Trumbowyg")
            )
        );

        return 1;
    }
}

ListPartViewModel Properties

| Property | Type | Description |

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

| ListPart | ListPart | The ListPart instance |

| ContentItems | IEnumerable<ContentItem> | The content items the list contains |

| ContainedContentTypeDefinitions | IEnumerable<ContentTypeDefinition> | The content types the list accepts |

| Context | BuildPartDisplayContext | The current display context |

| Pager | dynamic | The pager shape for pagination |

ListPartViewModel also exposes EnableOrdering, IsOrdering, ListPartFilterViewModel, and (in the admin) the List AdminListContext.

ListPartSettings Properties

| Property | Type | Description |

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

| PageSize | int | Number of content items per page (default 10) |

| EnableOrdering | bool | Enable drag-and-drop ordering of items |

| ContainedContentTypes | string[] | Content types that may be contained by this list |

| ShowHeader | bool | Show a header for the owning (container) content in the admin list |

| ShowFullPager | bool | Use the numbered Pager instead of PagerSlim |

Paging and Page Size Selection

Admin List

The list's contained items in the admin are rendered through the shared AdminList shape, so they follow the site's List or Grid layout. With EnableOrdering, an unfiltered admin list of the latest versions with more than one item forces the List layout and hides the layout selector; drag a row's handle to reorder (saved immediately). Searching or filtering disables drag ordering and restores normal layout selection. The List Items button names the contained content type.

Liquid Tags for Lists

`list_items` - Load Published List Items

The list_items filter loads published content items for a given content item or content item ID:

{% assign blogPosts = Model.ContentItem | list_items %}
{% for post in blogPosts %}
    {{ post | shape_build_display: "Summary" | shape_render }}
{% endfor %}

Load by content item ID:

{% assign blogPosts = "4j42fxryjcpqkkacmg6cwz3pr5" | list_items %}
{% for post in blogPosts %}
    <h2>{{ post.DisplayText }}</h2>
{% endfor %}
`list_count` - Count Published List Items
{% assign count = Model.ContentItem | list_count %}
<p>Total posts: {{ count }}</p>

Templating a ListPart with Liquid

Override the list rendering for a specific content type by creating a template named Blog-ListPart.liquid:

{% for item in Model.ContentItems %}
    {{ item | shape_build_display: "Summary" | shape_render }}
{% endfor %}

{% assign previousText = "Newer Posts" | t %}
{% assign nextText = "Older Posts" | t %}
{% assign previousClass = "previous" %}
{% assign nextClass = "next" %}

{% shape_pager Model.Pager previous_text: previousText, next_text: nextText,
    previous_class: previousClass, next_class: nextClass %}

{{ Model.Pager | shape_render }}

Templating a ListPart with Razor

Create a file named Blog-ListPart.cshtml:

@model OrchardCore.Lists.ViewModels.ListPartViewModel

@foreach (var item in Model.ContentItems)
{
    var shape = await ContentItemDisplayManager.BuildDisplayAsync(item, Model.Context.Updater, "Summary");
    @await DisplayAsync(shape)
}

@await DisplayAsync(Model.Pager)

Shape Alternates for ListPart

| Template Name | Filename | Description |

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

| ListPart | ListPart.cshtml | Default ListPart shape |

| Blog__ListPart | Blog-ListPart.cshtml | ListPart for Blog content type only |

| Blog_Summary__ListPart | Blog-ListPart.Summary.cshtml | ListPart for Blog in Summary display type |

| ListPartFeed | ListPartFeed.cshtml | RSS feed shape for ListPart |

Razor Helpers

The OrchardCore.Lists module provides IOrchardHelper helpers for querying list items programmatically:

| Method | Description |

|---|---|

| QueryListItemsCountAsync(listContentItemId, itemPredicate = null) | Count of contained items matching an optional ContentItemIndex predicate |

| QueryListItemsAsync(listContentItemId, itemPredicate = null) | Contained items matching an optional ContentItemIndex predicate |

@{
    var recent = await Orchard.QueryListItemsAsync(blogId, x => x.Published && x.CreatedUtc > DateTime.UtcNow.AddDays(-30));
}

Liquid also provides the container filter ({{ Model.ContentItem | container }}) to load the parent list of a contained item.

Querying Contained Items in Code

using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Lists.Indexes;
using YesSql;

var posts = await _session.Query<ContentItem>()
    .With<ContainedPartIndex>(x => x.ListContentItemId == blogId)
    .With<ContentItemIndex>(x => x.Published)
    .OrderByDescending(x => x.CreatedUtc)
    .Take(10)
    .ListAsync();

ContainedPartIndex stores ListContentItemId, ListContentType, ContentItemId, Order, Published, Latest, and DisplayText. It declares SingleRecordPerDocument() and ExclusiveToDocumentType() (YesSql 6.3), so a query joining only ContentItemIndex and ContainedPartIndex isn't grouped by document and its count doesn't join Document; joining another multi-record index (such as TaxonomyIndex) brings the grouping back. IContainerService (OrchardCore.Lists.Services) provides GetItemCountAsync(listContentItemId, ContainedItemOptions), QueryContainedItemsAsync(...) with a Pager or PagerSlim, GetNextOrderNumberAsync, and UpdateContentItemOrdersAsync. ContainedItemOptions.Status is Published (default), Latest, Draft, or Owner.

Feeds and GraphQL

ContainedPart Indexing

Every content item contained in a list has a ContainedPart with indexable properties:

| Index Field | Description |

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

| Content.ContentItem.ContainedPart.ListContentItemId | The parent list content item ID |

| Content.ContentItem.ContainedPart.Order | The display order of the item |

These are the field names in full-text indexes (Lucene, Elasticsearch, Azure AI Search).

Recipe: Creating a Blog with Posts

{
  "steps": [
    {
      "name": "Content",
      "data": [
        {
          "ContentItemId": "4j42fxryjcpqkkacmg6cwz3pr5",
          "ContentType": "Blog",
          "DisplayText": "My Blog",
          "Latest": true,
          "Published": true,
          "TitlePart": {
            "Title": "My Blog"
          },
          "AutoroutePart": {
            "Path": "blog"
          }
        },
        {
          "ContentItemId": "[js:uuid()]",
          "ContentType": "BlogPost",
          "DisplayText": "First Post",
          "Latest": true,
          "Published": true,
          "TitlePart": {
            "Title": "First Post"
          },
          "HtmlBodyPart": {
            "Html": "<p>Welcome to my first blog post!</p>"
          },
          "ContainedPart": {
            "ListContentItemId": "4j42fxryjcpqkkacmg6cwz3pr5",
            "Order": 0
          }
        }
      ]
    }
  ]
}
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.