Skip to main content

Add a component to a content type

Log in to add to favourites

Components are added to a content type as a field just like any other field, however the dataFormat of the field specifies the id of the component to add.

For example if you have a component with an id of "movieRole" then the dataFormat value would be "component.movieRole".

Example

JavaScript
existingContentType.fields.push({  
    "id":"movieRole",
    "name": {  
        "en-GB":"Movie Role"
    },
    "dataType":"object",
    "dataFormat":"component.movieRole",
    "description": {  
        "en-GB":"The movie Role"
    }
});

client.contentTypes.update(existingContentType)
  .then(result => {      
    console.log('API call result: ', result);              
  })
  .catch(error => {
    console.log('API call fetch error: ', error);      
  });

After a content type has been saved with a component field, all of the component's fields are added to a nested fields collection within the component field on the content type. A components' fields are read-only, and cannot be modified from the content type.

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request