lzb.editor.BlockEdit.attributesForRender
Filters the attributes sent to the server when the editor renders a block preview.
By default the list holds the values of the registered controls plus a few reserved attributes. Use this filter to add an attribute your own code stores on the block but that is not registered as a control, so the preview can render with it.
Attributes
| Name | Type | Description |
|---|---|---|
attsForRender | Object | attributes about to be sent for rendering |
data | Object | attributes, meta, lazyBlockData, props |
data.attributes holds every attribute on the block, including the ones left out of attsForRender.
Usage
wp.hooks.addFilter(
"lzb.editor.BlockEdit.attributesForRender",
"my.custom.namespace",
function (attsForRender, data) {
if (data.lazyBlockData.slug !== "lazyblock/my-block") {
return attsForRender;
}
return {
...attsForRender,
myCustomAttribute: data.attributes.myCustomAttribute,
};
}
);This affects the editor preview only. On the front end the block renders through PHP, where lzb/block_render/attributes does the same job.