CRAFTER:是否可以更改特定组件的特定属性的值?
CRAFTER: Is it possible to change the value of a specific attribute of a specific component?
我想知道是否有使用 Crafter Studio API 或 groovy 脚本仅更改特定组件中属性值的解决方案。
我唯一找到的是 API 的方法“Write Content”(https://docs.craftercms.org/en/3.0/developers/projects/studio/api/content/write-content.html) 但要仅更改一个属性,您需要检索整个组件文件,修改值你需要把整个文件推回去,这很重。
写内容API是目前唯一写内容的API
如果您正在使用 UI,您可以使用我们的 @craftercms/studio-ui
包轻松编写单个字段,因为这是为您抽象的。
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');
});
我想知道是否有使用 Crafter Studio API 或 groovy 脚本仅更改特定组件中属性值的解决方案。
我唯一找到的是 API 的方法“Write Content”(https://docs.craftercms.org/en/3.0/developers/projects/studio/api/content/write-content.html) 但要仅更改一个属性,您需要检索整个组件文件,修改值你需要把整个文件推回去,这很重。
写内容API是目前唯一写内容的API
如果您正在使用 UI,您可以使用我们的 @craftercms/studio-ui
包轻松编写单个字段,因为这是为您抽象的。
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');
});