Skip to content

feat: Allow block discriminator field in view columns#341

Open
antoniocosta wants to merge 1 commit intopages-cms:mainfrom
antoniocosta:feature/block-field-in-view-columns
Open

feat: Allow block discriminator field in view columns#341
antoniocosta wants to merge 1 commit intopages-cms:mainfrom
antoniocosta:feature/block-field-in-view-columns

Conversation

@antoniocosta
Copy link

Summary

This PR enables displaying the block discriminator field (e.g., _block) in collection view columns.

Problem

When using block fields, there's no way to display the block type in the list view. Users who want to show which block type each entry uses (e.g., "image", "video", "gallery") currently cannot do so because:

  1. getFieldByPath only traverses into object type fields, not block types
  2. Block fields are explicitly excluded from view columns

Solution

Modified getFieldByPath in lib/schema.ts to recognize the block discriminator field (defaulting to _block, or a custom blockKey if configured). When a path like content._block is requested, it returns a virtual string field definition.

Usage

In .pages.yml:

fields:
  - name: content
    type: block
    blocks:
      - name: image
        # ...
      - name: video
        # ...

view:
  fields: [title, date, content._block]

This will display "image", "video", etc. in the list view column.

Changes

  • lib/schema.ts: Extended getFieldByPath to handle block discriminator fields (~10 lines added)

Testing

Tested with a collection of 3300+ posts using various block types (image, video, gallery, quote, link, post). The column correctly displays the block type for each entry.

Enable displaying the block discriminator field (e.g., _block) in collection
view columns by extending getFieldByPath to recognize block fields.

When a path like 'content._block' is requested, returns a virtual string
field definition so the block type can be displayed in list views.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant