File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ const externals = [
4242 jquery : 'jQuery' , // import $ from 'jquery' // Use the WordPress version after enqueuing it.
4343 'react-dom' : 'ReactDOM' ,
4444 lodash : 'lodash' , // Lodash is there in Gutenberg.
45- CGB_GLOBAL : 'CGB_GLOBAL' // Add custom dynamic data to a global var .
45+ cgbGlobal : 'cgbGlobal' , // import cgbGlobal from 'cgbGlobal' // Localized data .
4646 }
4747) ;
4848
Original file line number Diff line number Diff line change @@ -53,13 +53,14 @@ function <% blockNamePHPLower %>_cgb_block_assets() { // phpcs:ignore
5353 null // filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
5454 );
5555
56- // Localise globals - plugin path and url for use in blocks .
56+ // Localised globals. Use dynamic PHP stuff in JavaScript via `cgbGlobal object .
5757 wp_localize_script (
5858 '<% blockNamePHPLower %>-cgb-block-js ' ,
59- 'CGB_GLOBAL ' , // Array containing dynamic data for a JS Global.
59+ 'cgbGlobal ' , // Array containing dynamic data for a JS Global.
6060 [
61- 'path ' => plugin_dir_path ( __FILE__ ),
62- 'url ' => plugin_dir_url ( __FILE__ ),
61+ 'pluginDirPath ' => plugin_dir_path ( __DIR__ ),
62+ 'pluginDirUrl ' => plugin_dir_url ( __DIR__ ),
63+ // Add more data here that you want to access from cgbGlobal object.
6364 ]
6465 );
6566
You can’t perform that action at this time.
0 commit comments