The component receives the following output:
{
__type: "article",
label: "Template verification article",
body: "<p>…</p>",
cover_image: {
__type: "image",
label: "acme.png",
media_image: {
alt: "Acme",
src: "/sites/default/files/2025-07/acme.png?alternateWidths=…"
}
},
author_profile: {
__type: "person",
label: "Ada Lovelace"
}
}Two details in the object require attention:
label, not title. To understand both concepts, review the following three rules.
To confirm any key, refer to the section on inspecting the value.
Three rules determine the keys in the delivered JavaScript object.
Some fields have a defined role for the content type, such as the title or the author. Those fields arrive under the role name rather than the field name. For Content, the fields map as follows:
Dialog box selection | Key in the prop value |
|---|---|
Title |
|
ID |
|
Revision ID |
|
Content type |
|
Published |
|
Authored by |
|
Other content entity types follow the same rule. The Name of a media item also arrives as label. The cover_image.label property in the previous example demonstrates this behavior. The Name of a taxonomy term follows the same pattern.
Every other field keeps its original name. Body arrives as body, Cover Image as cover_image, and the Image of the media item as media_image.
To produce body as a string, select only Body → Processed text.
To produce the image field as an object with the selected properties as keys, select both Image URL and Alternative text on an image field:
media_image: { src: "/sites/default/files/…", alt: "Acme" }When you select a field on referenced content, the system nests it under the key of the field that points to it. The nested object carries its own __type.
Images typically arrive in this format. A Cover Image field does not hold an image directly. It references a media item. Therefore, when you select the Image → Image URL of the media item, the system produces:
cover_image: {
__type: "image",
media_image: { src: "/sites/default/files/…" }
}The same rule applies to any reference. When you select Author profile → Title, it produces author_profile: { __type: "person", label: "Ada Lovelace" }.
A field that holds more than one value does not appear in the Content Relationship dialog box. The fields of the referenced content also do not appear. On an Article, fields such as Tags, Categories, and Related articles hold many values. Therefore, they do not appear in the list.
If an expected field does not appear, verify if the field configuration holds more than one value.
Each object at the top level and at every nested level includes a __type key. This key identifies the content type it represents. Use it when you must branch on the content type. Treat it as reserved.
Two independent elements can be missing. A robust component checks both elements.
null. This occurs when no content is referenced, when the referenced content is deleted, or when a content template maps an empty reference field. Never assume that the object exists.null. An article with no cover image yields cover_image: null instead of an object with empty values. A field can also change shape or disappear if the content type configuration changes later.Nested structures compound this behavior. To reach an image, you must pass through the reference, the media item, and the image field. Any of these elements can be missing.
Use optional chaining at every level.
const ArticleCard = ({ article }) => {
if (!article) {
return null;
}
const { label, body, cover_image: cover, author_profile: author } = article;
const image = cover?.media_image;
return (
<article>
{image?.src && <img src={image.src} alt={image.alt ?? ''} />}
{label && <h3>{label}</h3>}
{author?.label && <p>By {author.label}</p>}
{body && <div dangerouslySetInnerHTML={{ __html: body }} />}
</article>
);
};
export default ArticleCard;Because the interface does not display key names, confirm them when you render the value. Temporarily replace the output of the component with the value itself:
const Component = ({ article }) => JSON.stringify(article, null, 2);
export default Component;Then:
The preview displays exactly what your code receives. This includes __type, the renamed keys, and any nested structures. Restore the real output of your component after you finish.
Perform this action whenever you add or change a field selection. Ensure that you do this before you write code against a field that you added to the content type.
If you work with a local codebase, print the resolved value. With this approach, you do not need to place the component on a page. This method is faster than the page preview when you iterate on a field selection.
The command reads the component from your local project and requests the site to resolve the fields against a real piece of content. Therefore, a component that you author in the browser remains invisible to the command until you pull the component to your local environment.
To print the resolved value from a local codebase:
CANVAS_SITE_URL, CANVAS_CLIENT_ID, and CANVAS_CLIENT_SECRET variables. npx canvas pullnpx canvas agents-context cer-preview <component-id>
The output is the same object that your code receives. This includes __type, the renamed keys, and any nested structures.
If the command reports that the component is missing, it searches in your local project instead of the site. Run the npx canvas pull command first.
The Preview pane inside the code editor does not resolve content entity reference props. The pane has no selected content. Therefore, the prop arrives as an empty string instead of an object or a null value.
This behavior has two consequences:
The system resolves field values against the permissions of the person who views the page. The system checks permissions for every piece of content that the prop reaches. This includes content reached when you follow a reference.
If a viewer does not have permission to view the referenced content, the component does not silently omit the field. Instead, the page fails to render that component. This behavior is critical when you follow a reference into non-public content, such as the account of the author who created an article. Select fields from referenced content only when every viewer has permission to view that content.
When you select fields, Drupal Canvas records the content type and those specific fields as component requirements. A component that reads the body and image of an article requires a site where the Article type contains those fields with the exact configuration.
The practical effects include:
Select only the required fields.
If this content did not answer your questions, try searching or contacting our support team for further assistance.
If this content did not answer your questions, try searching or contacting our support team for further assistance.