In the edit method for your custom block, when rendering the components you can use the “conditional + &&” pattern:
<PanelBody title={ __( 'My Panel' ) } >
{ myCustomBool &&
<MyComponent
value={theValue}
onChange={ value => {
myChangeCallback(value);
} }
/>
}
{ 'marmots' !== myCustomThing &&
<MyOtherComponent
value={theValue}
onChange={ value => {
myOtherCallback(value);
} }
/>
}
</PanelBody>
In the above example, the conditionals just before the “&&” will determine whether the component that follows will be rendered.
This is sometimes referred to as a “short circuit conditional”.
Related Posts:
- Enable Gutenberg on custom post type
- Add class to Gutenberg Editor for Custom Post Types
- How to filter by custom post type on Gutenberg “Latest Posts’ block
- Gutenberg: Sidebar for specific post type
- Gutenberg how to make attribute to save to meta
- How to add button to post page WordPress 5.x
- WordPress Gutenberg-Block with ESNext (withState, withSelect)
- The editor has encountered an unexpected error. // TypeError: Cannot read property ‘prefix’ of null
- Display different gutenberg template from selected post attributes
- WordPress Rest API only returns content when posttype has editor capability
- Lock post meta block at the bottom of a custom post type
- How can I list all custom post types in a block
- Gutenberg Featured-Image-panel missing when user with custom role edits Custom Post Type
- Adding a Gutenberg-like custom field on a custom post type
- Classic editor showing in Gutenberg when creating a custom post type
- Creating template with h3 block (block editor)
- How To Enable Block Editor (Gutenberg) for Existing Post Type via functions.php
- How to make a custom taxonomy selectable in post publish area?
- show_in_rest false disable Gutenberg
- I can’t choose the custom taxonomy in my custom post type on Gutenberg
- Parent field missing from custom post type in the block editor
- How to get the parent of a non-hierarchical custom post type being edited in Gutenberg
- post_type_link not working in gutenberg
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Getting meta in editor plugin, and event triggering issue
- Save the post parent in a custom post type in Gutenberg
- WordPress CPT save metadata in gutenberg
- Can I override a CPT template on a per post basis with Gutenberg block editor?
- Query Post Object in WP Admin
- How to display “Category and Post_tag” component in a CPT Gutenberg edit screen?
- Combine multiple getEntityRecords calls
- Custom post type editor uses old tinyMCE
- Use core block functionality in a custom block gutenberg
- gutenberg message
- How do I assign a block template (.html) to a custom post type?
- Custom post type set default template using block editor
- CPT: Enable Gutenberg, but disable editor field
- Select custom post type do display from page editor
- How add Filter by Tags and by categories to custom post type in Gutenberg block
- Is it possible to add the Gutenberg block editor to a custom taxonomy?
- How to debug failing updates for custom post type?
- Some posts not displaying by taxonomy term
- Can you programme the selected page template to display block patterns automatically?
- Possible to limit internal link search to post types with Gutenberg editor?
- Custom Gutenberg block problem – This block has encountered an error and cannot be previewed
- getEntityRecords/useEntityRecords: How to use CPT metadata?
- Custom Block: Adding “Post Type” dropdown to Sidebar Settings
- Post term block variations not generated for custom taxonomies
- Can’t publish custom type posts that don’t support title and editor, instead they’re saved as draft
- How To Limit Hierarchical Pages Depth (For Custom Post Types) To Children Only
- How to remove “featured image” functionality from a custom post type?
- Using /%postname% for a custom post type
- Show custom post type endpoint in REST API just if user has capability
- How Can the Users Make a “Playlist” of Posts?
- Glossary with Custom Post Type
- Automatically assign a custom post to a custom taxonomy based on custom field value
- Exclude Custom Post Type & Pages From Auto-Tag Function
- Displaying custom post type on category pages but not on blog listings
- How to stop subdirectory wordpress install adding head elemets to entire site?
- How to add post_author column to custom post type
- Rendering Custom Post Types independently of the theme in use
- Sort by two dates. Default entry date and custom field if present
- Issue to get wp_get_attachment_image with cmb2
- Made Custom Post Types, but single.php not working
- How do I get Link for Oldest Custom Post Type (dynamically)
- Pagination : How to remove /page/x/ after a ‘POST’ action on a form returning to page 1
- Archives for Custom Post Types (without Pages)
- Shortcode for display posts in wp-editor
- Insert post metadata for all posts in CPT at once if metadata no existent
- Is there a way to have custom post type and page with the same slug?
- Admin Pointers on a custom post type
- How can I move (or create another) publish button?
- Wrap meta boxes & data handling for specific post types in classes?
- WP Query post__in not returning correct results
- get_the_post_thumbnail_url(‘full’) returns empty from custom post type
- Query multiple taxonomies with pre get posts
- How to set up Custom Post Type archive page as Front page
- Give each post type label a different color?
- Custom Permalinks For CPT and pages with parent. Advanced WordPress
- How to add a filter to a custom post type to get adjacent custom posts via the REST API
- I’m trying to create a custom version of the wp_list_authors function that includes custom post types
- Plain links in single-class.php and archive-class.php not working
- How can I get 3 different taxonomy type terms in a div class element?
- Custom post rewrite rule not working
- 2 Custom Post Types In 1 Archive Page?
- Why it doesn’t create a custom post type after form submitting
- What is the correct way that when creating a custom post type assign values to custom fields created with pods framework?
- Guided post type create based on category tree
- Advanced search form with multiple custom fields
- Custom Field Filter by Role – WordPress
- Adding Custom Taxonomy Along-with Post Name in Post Type Permalink
- archive.php can’t find categorized posts
- Submiting custom form give error 404
- Metabox textarea showing whitescreen
- How to loose the image ‘alt’ attribute in my custom post type?
- Cannot exclude particular post from loop of custom post type
- Apply text based styling done for a single post in WPBakery to all posts / create a template out of it [closed]
- Custom archive URL as a subfolder of the custom post type slug
- get_post_types() is returning null
- How can I show a field ID in Elementor with Request Parameter