Add media dynamically on gutenberg block

I want to make a carousel gallery with WordPress Gutenberg but I'm facing an dilemma. How do I add images dynamical

I want to make a carousel gallery with WordPress Gutenberg but I'm facing an dilemma. How do I add images dynamically?

I could go and add like 10 MediaUpload but this isn't very reliable.

I'm thinking about a button that might create MediaUpload

el(MediaUpload, {
    onSelect: onSelectInfoImage,
    type: 'image',
    value: attributes.smallMediaURL,
    render: function (obj) {
      return el(components.Button, {
        className: attributes.smallMediaID ? 'image-button' : 'button button-large',
        onClick: obj.open
      },
      !attributes.smallMediaID ? i18n.__('Bild hochladen') : el('img', { src: attributes.smallMediaURL })
      )
    }
})

and the button should be something like

el(IconButton,{
    className: 'media-create',
    icon: 'no',
    label: 'Add slide',
    onClick: function (media) {
        ***spawn new media***
      }
})

I want to make a carousel gallery with WordPress Gutenberg but I'm facing an dilemma. How do I add images dynamically?

I could go and add like 10 MediaUpload but this isn't very reliable.

I'm thinking about a button that might create MediaUpload

el(MediaUpload, {
    onSelect: onSelectInfoImage,
    type: 'image',
    value: attributes.smallMediaURL,
    render: function (obj) {
      return el(components.Button, {
        className: attributes.smallMediaID ? 'image-button' : 'button button-large',
        onClick: obj.open
      },
      !attributes.smallMediaID ? i18n.__('Bild hochladen') : el('img', { src: attributes.smallMediaURL })
      )
    }
})

and the button should be something like

el(IconButton,{
    className: 'media-create',
    icon: 'no',
    label: 'Add slide',
    onClick: function (media) {
        ***spawn new media***
      }
})
Share Improve this question asked Mar 21, 2019 at 10:44 Razvan CuceuRazvan Cuceu 2482 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default -1

You can set the multiple and gallery props to {true} which enables to select multiple images and make a gallery. More information in the GitHub readme: https://github/WordPress/gutenberg/tree/master/packages/block-editor/src/components/media-upload

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745385215a4625409.html

相关推荐

  • Add media dynamically on gutenberg block

    I want to make a carousel gallery with WordPress Gutenberg but I'm facing an dilemma. How do I add images dynamical

    4小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信