From 03714f8d1bd83eab92eaa45d6cb8341d9cb9bba3 Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Mon, 6 Mar 2017 17:57:43 -0500 Subject: [PATCH] add documentation for widgetsFor helper --- docs/extending.md | 92 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 1 deletion(-) diff --git a/docs/extending.md b/docs/extending.md index 2fb44d23..82d4d57d 100644 --- a/docs/extending.md +++ b/docs/extending.md @@ -37,9 +37,10 @@ Registers a template for a collection. **React Component Props:** * collection: The name of the collection which this preview component will be used for. -* react_component: A React component that renders the collection data. Three props will be passed to your component during render: +* react_component: A React component that renders the collection data. Four props will be passed to your component during render: * entry: Immutable collection containing the entry data. * widgetFor: Returns the appropriate widget preview component for a given field. + * [widgetsFor](#lists-and-objects): Returns an array of objects with widgets and associated field data. For use with list and object type entries. * getAsset: Returns the correct filePath or in-memory preview for uploaded images. **Example:** @@ -63,6 +64,95 @@ CMS.registerPreviewTemplate("posts", PostPreview); ``` +### Lists and Objects +The API for accessing the individual fields of list and object type entries is similar to the API +for accessing fields in standard entries, but there are a few key differences. Access to these +nested fields is facilitated through the `widgetsFor` function, which is passed to the preview +template component during render. + +**Note**: as is often the case with the Netlify CMS API, arrays and objects are created with +Immutable.js. If some of the methods that we use are unfamiliar, such as `getIn`, check out +[their docs](https://facebook.github.io/immutable-js/docs/#/) to get a better understanding. + +**List Example:** + +```html + +``` + +**Object Example:** + +```html + +``` + ### Accessing Metadata Preview Components also receive an additional prop: `fieldsMetaData`. It contains aditional information (besides the plain plain textual value of each field) that can be useful for preview purposes.