I am basically creating a Custom Carousel Gutenberg Block. It qould be a carousel at the front end and I plan on using a Gallery Block to add images to the carousel.
The carousel would be loaded using bxSlider which requires a certain syntax as you can see here. The gallery renders a different syntax at the front-end (a list based output of Images). I want to modify the syntax of the rendered gallery.
The render_callback
argument seems to modify the output but for that to work, I need IDs of all the images in the Gallery.
The closest I have come to a way out is in this thread using data modules and withDispatch
component to retrieve data but I have no Idea how to use it in JSX script. This is the script for my custom block-
const { registerBlockType } = wp.blocks;
const { InnerBlocks } = wp.blockEditor;
const ALLOWED_BLOCKS_GALLERY = ['core/gallery'];
const GALLERY_TEMPLATE = [
['core/gallery', {} ]
];
registerBlockType('my-plugin/my-plugin-carousel', {
title: 'Carousel',
description: 'Insert a Carousel using Images from Gallery',
category: 'common',
icon: {
src: 'image-flip-horizontal',
foreground: '#1d7eb6'
},
attributes: {},
edit: (props) => {
return([
<div className="my-carousel-container">
<InnerBlocks allowedBlocks={ ALLOWED_BLOCKS_GALLERY } template={ GALLERY_TEMPLATE } templateLock="insert"/>
</div>
])
},
save: () => {
return <InnerBlocks.Content />
}
});
Any help on how to proceed with this situation will be highly appreciated! I have spent the last two days on this and have nothing to show for it.