Este es mi archivo block.js. En la cuarta línea, tengo MediaUpload var, debajo quiero la identificación de la publicación actual. ¿Cómo puedo obtenerlo?
( function( blocks, editor, i18n, element, components, _ ) { var el = element.createElement; var RichText = editor.RichText; var MediaUpload = editor.MediaUpload; blocks.registerBlockType( 'gutenberg-examples/example-05-recipe-card', { title: i18n.__( 'Author card', 'gutenberg-examples' ), icon: 'index-card', category: 'layout', attributes: { writer: { type: 'array', source: 'children', selector: 'h2', }, photography: { type: 'array', source: 'children', selector: 'h2', },El contexto del bloque accede al postId actual agregando usesContext al registrar el tipo de bloque, por ejemplo:
blocks.registerBlockType( 'gutenberg-examples/example-05-recipe-card', { title: i18n.__( 'Author card', 'gutenberg-examples' ), icon: 'index-card', category: 'layout', attributes: {...}, usesContext: [ 'postId' ] }); Al incluir contexto en su función de edit({attributes, setAttributes, context}) , tendrá acceso a la ID de publicación actual con:
edit({attributes, setAttributes, context}){ const {postId} = context; }