You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For static blocks we can use the registerBlockExtension to easily add additional classnames. Technically it also works for adding inline styles but we should use that sparingly because it may introduce block validation issues and deprecations.
Another issue is that the block extensions only apply to static blocks. When the rendering happens on the server in PHP it doesn't do anything.
To solve for all these usecases we can use the HTMLTagProcessor and the block render callbacks.
Here is a quick example for adding an animation extension:
JS that deals with the editor:
/** * additional block attributes object */constANIMATION_ATTRIBUTES={animation: {type: 'object',default: {},},};/** * generateClassNames * * a function to generate the new className string that should get added to * the wrapping element of the block. * * @param {object} attributes block attributes * @returns {string} className string */functiongenerateClassNames(attributes){const{ animation }=attributes;if(!animation?.name){return'';}constclassNames=['has-block-animation',animation.name,`duration-${animation?.duration||300}`,];if(animation?.delay){classNames.push(`delay-${animation.delay}`);}if(animation?.easing){classNames.push(`timing-${animation.easing}`);}constclassNameString=classNames.join(' ');returnclassNameString;}registerBlockExtension(window.AnimateBlocks.blocks,{extensionName: 'tenup/animate-blocks',attributes: ANIMATION_ATTRIBUTES,classNameGenerator: generateClassNames,Edit: BlockEdit,});
PHP to register the additional attribute for all blocks
@fabiankaegy Hii, I was looking through your code and I am interested in contributing. I have a basic understanding of js but I have no prior knowledge of php so I am unable to understand the entire codebase . Please help me out here
For static blocks we can use the
registerBlockExtension
to easily add additional classnames. Technically it also works for adding inline styles but we should use that sparingly because it may introduce block validation issues and deprecations.Another issue is that the block extensions only apply to static blocks. When the rendering happens on the server in PHP it doesn't do anything.
To solve for all these usecases we can use the
HTMLTagProcessor
and the block render callbacks.Here is a quick example for adding an animation extension:
JS that deals with the editor:
PHP to register the additional attribute for all blocks
PHP to add the actual output to the block on the server:
The text was updated successfully, but these errors were encountered: