You can use wp_localize_script() to pass JavaScript variables to the editor:
$asset_file = include(get_template_directory() . '/path/to/blocks/index.asset.php');
wp_register_script(
'pb-theme-blocks',
get_template_directory_uri() . '/path/to/blocks/index.js',
$asset_file['dependencies'],
$asset_file['version']
);
wp_localize_script(
'pb-theme-blocks',
'pbThemeBlocksVars',
array(
'classes' => array(), // Your theme classes go here
)
);
Then in your edit function:
const classes = pbThemeBlocksVars.classes;
Related Posts:
- Gutenberg Blocks doesn’t render correctly when using do_blocks
- Create custom blocks for bootstrap
- Passing the name of selected color from the custom component to `render_callback`
- WordPress – Get Posts with Category data
- register dependency css and js inside a plugin class
- How to remove hardcoded characters from playlists?
- Conditionally loading JavaScript based on the Advanced Custom Fields in the post
- add_meta_boxes action with refresh on save
- How to use copy() function and paste file in /wp-content/themes directory
- Understanding WordPress child theme custom JS loading
- Use different javascript files for each page on website
- do not show web page section when using advanced custom fields pro
- Am I not understanding plugins?
- Using Font Awesome as post thumbnail
- Why WordPress architecture is not pure object oriented and it don’t use MVC pattern? [closed]
- admin-ajax.php responding with 0
- Page Reloads Before AJAX Request Finishes
- custom shortcode will not display the wrapped content
- How to test nonce with AJAX – Plugin development
- Trigger popup in a php if/else statement
- How can i upload images in an admin page?
- How to select the contents in the text view textrea in wp_editor?
- Hide categories that are not used in the post type
- Displaying admin notices inside the block editor from rest_after_insert_{$this->post_type} hook
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- what is the best practice to add new field to an api route
- I have a problem in the order of enqueues while enqueuing stylesheets and scripts for a specific page in my function.php
- Need Help Fixing My Iframes [closed]
- Improve page speed loading using CDN and async or defer attribute
- How to send Ajax request from my plugin in admin dashboard?
- Menu jumping when calling it via PHP
- AJAX success response is not working but it’s saving my changes
- Redirect to another page using contact form 7? [closed]
- How to obtain the current website URL in my theme?
- What exactly do this function declared into functions.php file of a WP theme?
- Is it save to use eval for a jQuery callback method coming from the database?
- zip unzip attachments in wordpress
- wordpress admin plugin menu custom css
- How to add the sidebar to all the pages except the home page? [closed]
- How to Change CSS Colors from Custom Plugin Settings Page
- wp_nav_menu not working correctly in my underscores theme
- Validate and Sanitize WP REST API Request using WP JSON Schema?
- How can I search all plugins for composer’s vendor/autoload.php?
- Removed jQuery script from header.php , any problems?
- Toolbar Hidden in a Virtual Page
- Ajax URLs without #!, how to prevent falling into single.php on load or reload?
- security concerns if using html data-* attribute for l10n?
- How to use wp_send_json() and output the value with ajax?
- Additional file upload in Gutenberg page options/featured image
- How to populate a Gutenberg select field SelectControl with option value from PHP array
- Settings API form – submit with AJAX
- How to change basename url for wp-admin?
- Post form – AJAX won’t upload featured image – Plugin development
- Gutenberg block don’t save rich text content
- Creating a POP Alert
- How do I disable cache for a certain page?
- Submit remote form to wordpress REST API and save data to custom post type
- Store user form submitted information in post type
- Display attached images of a page or post that are insetred using gallery
- Add a custom link to each image in WordPress gallery
- Collapsible menu on post sidebar only expands and does not collapse
- How to properly escape in ternary operators – Wp Coding Standards?
- How to send Ajax Call from frontend without using wp_localize_script in Theme
- How to use Amazon Elastic Transcoder from WordPress using AWS SDK for PHP?
- Why this plugin is not working?
- WP multisite network plugin fails to see classes loaded with spl autoload
- How to edit the default database of WordPress [closed]
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- How to create post comparison in wordpress
- Import js variables loaded via wp_localize_script() into js module without global scope connection
- Variable ++ in query loop
- Add default block css when the block has been added with php?
- Woocommerce Convert existing order to the cart
- Manipulating the allowed inner blocks of a core-gutenberg-block?
- Capture the Selected Radio Button Value between two files in wordpress theme
- how to escape alert/window.location.replace with variable
- Adding features to Gutenberg without theme.json
- JQuery UI Autocomplete showing as bullets
- useBlockProps() nests wrapper with class name inside block wrapper in the editor
- Add custom data attribute to every core Gutenberg Blocks
- Embed dynamic media query in a Gutenberg block
- Add Imports to Existing WordPress Import Map
- How to get the content of a dynamic block in PHP
- Is it possible to use the featured image of a page as a css background without inlining?
- Using shipped version of jquery
- WP add_action factory
- How to show phpinfo() only in a new tab?
- Populate dropdown with Child Pages based on Parent Page chosen
- How can I remove a function that has been added to wordpress with add_filter?
- Link to page with posts of specific type
- random reason on refresh
- How to tell if a user has gone in and created a menu
- Change Query Arguments (filter) with jQuery/Ajax or PHP?
- How To Get HTML Eelement From Another Page
- add custom link to gallery images
- Force ‘permanent’ post cache of shortcode results
- Transate plugin with js & wp_localize_script
- WP Custom tables query
- Date not working correctly
- What is considered good practice for registering menu locations?