0

I was wondering if there is a solution to only change the value of an attribute in a specific component using the Crafter Studio API or a groovy script.

The only thing I have found is the method "Write Content"(https://docs.craftercms.org/en/3.0/developers/projects/studio/api/content/write-content.html) of the API but to only change one attribute you need to retrieve the entire component file, modify the value you need and push the entire file back, that is quite heavy.

Lana James
  • 77
  • 9

1 Answers1

1

Write content API is the only API that writes content at the moment.

If you're working on the UI, you could use our @craftercms/studio-ui package to write single fields easily as this is abstracted for you there.

yarn|npm install @craftercms/studio-ui
import { updateField } from '@craftercms/studio-ui/services/content'
updateField(
  'yourSiteId',
  '/path/of/the/xml/or/objectId/if/embedded.xml',
  'idOfTheField_s',
  indexOfItem, // If it is a collection (node-selector, or repeat group), send null otherwise,
  parentModelId, // null unless you're working with embedded content
  newValueOfTheField
).subscribe(() => {
  console.log('Field update complete');
});
sumerz
  • 1,346
  • 7
  • 4