Unable to access ckeditor custom fields when set on assets
Nobody has claimed this yet.
- 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
- create new custom field for assets, as described on https://craftcms.com/docs/5.x/reference/element-types/assets.html#asset-custom-fields
- add contents to the custom field on an example entry with assets
- try to output the custom field in the frontend with twig code
{{ image.caption }} - 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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