craftcms / craftcms/ckeditor

Unable to access ckeditor custom fields when set on assets

Open
#355 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
47
Forks
32
PR merge metrics
No merged PRs in 30d

Description

Description

We've set a custom field for all assets on a craft 5 installation, which works well as long as the custom field is the native plain-text field from craft. But as soon as the custom field is set as ckeditor field, it is not accessible anymore on the frontend via twig functions. Is this out of reach for the ckeditor plugin, or should it be accessible?

In more detail, we have created a custom field with name "caption" (to be used additionally to the native alt-field). when set to plain text, outputting it works well by using {{ image.caption }} (after the needed image-query) – but as soon as the field is a ckeditor-field it's an empty output.

Steps to reproduce
  1. create new custom field for assets, as described on https://craftcms.com/docs/5.x/reference/element-types/assets.html#asset-custom-fields
  2. add contents to the custom field on an example entry with assets
  3. try to output the custom field in the frontend with twig code {{ image.caption }}
  4. other way that have been tried: {{ image.caption.getContent() }} or {{ image.getFieldLayout().getCustomFields()|map(field => field.handle == 'caption' ? field.getContent() : null)|first }} which all result in errors cause image.caption is empty for ckeditor fields.
Additional info
  • Craft version: 5.5.10
  • PHP version: 8.2.27
  • Plugins & versions: CKEditor 4.4.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with a Craft 5.5.10 asset custom field using CKEditor 4.4.0, then inspect the frontend Twig access paths described in the issue. Done means determining whether the caption value is available through image.caption or the listed field-layout access and covering the expected behavior with an appropriate test.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.