微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从自定义Gutenberg块的内部块中的Gallery块获取图像ID

如何解决从自定义Gutenberg块的内部块中的Gallery块获取图像ID

我基本上是在创建Custom Carousel Gutenberg Block。它应该是前端的旋转木马,我计划使用gallery Block将图像添加到旋转木马。

轮播将使用bxSlider加载,这需要某种语法,如您所见here。画廊在前端(基于列表的图像输出)呈现不同的语法。我想修改渲染图库的语法。

render_callback参数似乎修改输出,但要使其正常工作,我需要图库中所有图像的ID。

我发现最接近的解决方法in this thread使用数据模块和withdispatch组件来检索数据,但是我不知道如何在JSX脚本中使用它。这是我的自定义块的脚本-

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 />
    }
});

我们将非常感谢您提供任何有关如何处理这种情况的帮助!我花了最后两天的时间,对此无可奉告。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。