UI extensions - File structure
UI extensions - File structure
The minimal file structure of extensions consists of two files:
- An HTML file (e.g.
index.html) which holds the code of the extension - A JSON file (e.g.
extension.json) which describes the extension’s properties such asnameor the supported field types
Let’s take a closer look at these files to understand what they do.
Source code: index.html
The index.html file is the building block for an extension and it is embedded into the Contentful entry editor as an <iframe>.
The index.html includes the following:
-
the markup code and the logic.
-
reference to the App SDK which,
-
enables the extension to communicate with the Contentful web app.
-
exposes the
contentfulApp.init()method. This is the main entry point for all the extension-related code.
-
Following is an example of the contentfulApp.init() method:
Descriptor file: extension.json
The extension.json file, also known as the Descriptor file, is used to describe the properties of an extension. Although this file is optional, it is recommended to create it. The Contentful CLI is supporting descriptor files. Descriptor files should be committed to version control next to the source code of the extension as they describe the configuration fo the extension.
The following table describes the properties that can be set on an extension.
* Valid field types are: Symbol, Symbols, Text, Integer, Number, Date, Boolean, Object, Entry, Entries, Asset, Assets.
Following is an example of a extension.json file: