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
- Get terms by taxonomy AND post_type
- How to remove slug from hierarchical custom types in 3.5.2
- Featured Image Panel Missing From Custom Post Type in WordPress 3.2
- Getting a list of custom posts by author
- Is there a way to use regular categories with custom post types?
- Add Custom Post Type to Current Query
- Add Post type menu to another menu
- Getting Bootstrap accordion working in WordPress loop with custom post type (collapsing issue)
- “pagination” (but not really) and queries using custom posts types
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)
- action init hook and get_post_types
- Website bookmarks as a custom post type
- grant a privilege for roles (for example editors) and higher
- Multiple information using custom post type
- Related links – from other sites
- Custom columns for multiple custom post types
- post_row_actions not working for hierarchical post type
- Am I using the flush_rewrite_rules function in the right place?
- How should I structure my post types?
- Post Quote with image on header for news site
- 301 redirect for converted post type
- Custom post types team data
- WordPress permalink / slug with numbers in the middle of the post name shows the broken page
- Display post as term id
- WordPress custom post type permalink rewrite shows page not found
- Custom Post Type and Category Base Rewrite Issue
- Order a custom post type admin screen by a second custom post type title
- Custom post type conditional in loop
- Showing specific post in order of array wp_query
- Understanding Post Formats/Custom Post types Etc
- How to get dropdown instance value in WordPress custom Widget
- Break up posts per page in two sections
- WordPress custom post categories and subcategories on category.php
- Can’t replace the default sidebar with a custom sidebar on Custom Post Type in Genesis
- Two queries – one with checkbox ticked, one without – comparing meta_query
- custom post archive URL is wrong
- Can I decide what categories show on my posts page?
- How do I call the custom Post Type name and permanent link to my php file?
- Mandatory field in Custom post
- Link custom post type to users membership
- In child theme, add CPT to custom taxonomy registered in parent theme
- How to display posts with plugin (advanced custom fields) field groups?
- Load info from customposttype into template page
- Multiple Loops In Tabs Only Displaying First Loop
- How to create groups like that in buddypress?
- Include template if a post is a single product
- Allow viewing the edit screen for a post type, but not make/save/publish/update changes
- Render custom taxonomy query as single template
- General question about Parent and Child Post type relationships
- What’s the best way to show custom post types? With page template it’s not perfect!
- How to write an if statement which reads: ‘if is this custom post type or a child of it do the following’?
- Post count for particular term
- Show custom category archive as front page and remove taxonomy slug from urls