Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional Blocks? #6866

Closed
bahia0019 opened this issue May 21, 2018 · 21 comments
Closed

Conditional Blocks? #6866

bahia0019 opened this issue May 21, 2018 · 21 comments
Labels
[Status] Needs More Info Follow-up required in order to be actionable. [Type] Question Questions about the design or development of the editor.

Comments

@bahia0019
Copy link

Is there a plan for a conditional block?

@gziolo gziolo added the [Status] Needs More Info Follow-up required in order to be actionable. label May 21, 2018
@gziolo
Copy link
Member

gziolo commented May 21, 2018

Can you share more details about your idea? How do you see it working exactly? Is there any particular use case you have that it would solve?

@gziolo gziolo added the [Type] Question Questions about the design or development of the editor. label May 21, 2018
@bahia0019
Copy link
Author

Hi Greg,
If you're familiar with ACF, you may already use it quite a bit.

Say you have a Landing Page, and you have a variety of blocks dealing with your business. In a list maybe they're like:

  1. Business hours.
  2. Services.
  3. Rates.
  4. Location/Address.

But, you want to only show 1 and 4 if the business is a brick and mortar.
So you have a toggle at the top asking "Does your business have a physical location?"
I the answer is yes, the blocks 1&4 would be programmed to display.

That would be an example of a conditional.
There are likely better examples, but that's just what I was able to think of at 2am.

@Soean
Copy link
Member

Soean commented May 21, 2018

Related: There is already a plugin called Block Options https://wordpress.org/plugins/block-options/

@bahia0019
Copy link
Author

bahia0019 commented May 21, 2018

@Soean Eh... Doesn't look like all that much really.
One, I'm not a fan of adding more plugins for something that I think people will ultimately want natively.
Two, the conditional component to that plugin requires the user to actually write PHP and use WordPress functions (this may be something you and I can do, but not practical for an end user).

I appreciate you suggesting something, but this doesn't really come close to a solution for what I'm proposing/asking about.

@Soean
Copy link
Member

Soean commented May 22, 2018

@bahia0019 I know its not a perfect solution, I just wanted to post it as an example https://block-options.com/features/. So you should see it more as an Inspiration. I like to see this kind of feature in core.

@phpbits
Copy link
Contributor

phpbits commented May 24, 2018

@Soean Thank you very much for suggesting Block Options! @bahia0019 you can use the Display Logic option to add conditional statement. I do have more features that will be very helpful for what you are looking for. Will keep you posted once those features are available. Cheers!

@danielbachhuber
Copy link
Member

Closing, as it seems like this can be addressed with a plugin for the time being.

@phpbits
Copy link
Contributor

phpbits commented Jul 19, 2018

@bahia0019 I've decided to add ACF support already to Block Options plugin :) I haven't uploaded this feature yet but here's the preview. Let me know if you're up for testing. Thank you very much!

screen capture on 2018-07-19 at 16-54-06

@bahia0019
Copy link
Author

@phpbits I don't understand what that is supposed to do.
My suggestion was to include native conditional logic AND eliminate a dependency on ACF.

@phpbits
Copy link
Contributor

phpbits commented Jul 20, 2018

@bahia0019 sorry, I misunderstood! I thought you are looking for a way to make the block visibility dependent on ACF.

@paaljoachim
Copy link
Contributor

paaljoachim commented Dec 27, 2018

I do believe a conditional block would be great to have for various elements of a page that we would like to define where these are to be seen. Inside a conditional block one could add a sidebar/footer/menu/header or any other block.

Btw Perhaps even add conditional logic to the container block. (I am not able to find the issue for the container block right now.) The container block is meant to have child blocks inside of it.

It would be great to add a phase two label to this issue @danielbachhuber @melchoyce

This was referenced Dec 27, 2018
@jwold
Copy link

jwold commented Dec 27, 2018

@paaljoachim this is intriguing!

How exactly would the conditional logic work in this case? My concern is that the steps shown above might be a bit much for the use case we've been discussing on the Make blog. If I'm going to add a conditional block, I more care about just saying "this goes across the entire site".

I welcome thoughts on this! At the moment it feels like the use case for conditionals might need some tweaking to fit for something such as the nav block.

Thanks!

@paaljoachim
Copy link
Contributor

paaljoachim commented Dec 27, 2018

Hey @jwold

Most blocks have an advanced area in the sidebar settings. I would suggest that we actually use it. (Today it seems to mainly be used to create another CSS class.)

How to easily setup conditionals is something we will need to look closer at.
Here is a suggestion.

gutenberg-conditionals

By using the Advanced section.
Adding a Where to show Container Block.
Then an accordion listing all pages. Another listing posts.
Then an is user logged in.

This is what it could look like when open. Clicking the Pages accordion then shows all the pages. User clicks the pages and they get listed next to the Pages title showing which pages the container will be seen in. Similar to when selecting a color one sees the color preview tiny box next to the color background title. As it gives an overview of what has been selected.

gutenberg-conditionals-open

Of course I am probably missing conditionals that should be added, but it gives a nice overview of how I see it can be done.

@jwold
Copy link

jwold commented Dec 27, 2018

Ok, this is becoming clearer to me. Thanks for clarifying!

  1. I think this is worth feeling out and seeing what kind of feedback is received on using it, or at least playing with a prototype.

This is what it could look like when open. Clicking the Pages accordion then shows all the pages.

  1. We may also want to think of a "select all" use case, and then manually unchecking the blocks. I think that's normal behavior already for tags/categories.

@caringdesign
Copy link

For a use case, I just wanted to add a couple of thoughts based I'm something I'm looking at doing:

  1. Alert or warning based on connection to another site such as weather alerts. ifAlert then displays block(s) with a warning and possibly recommended actions.

  2. Display of block based on user conditions (Role/permissions, number of posts created, pending posts to review, pending comments, etc.) Some functionality already exists but could be created without adding more plug-ins.

If a conditional engine is built, with maybe a few conditions to start, others may create add-on conditions just as others are now coming up with add-on blocks. In fact, some creating specific blocks, such as a weather type block above, might come up with their own conditions specific to the block they designed.

Just adding more thoughts.

Thanks!
Ken

@drivendevelopment
Copy link

Wicked Block Conditions can be used to show or hide blocks based on conditions like user login status and role.

@lkraav
Copy link

lkraav commented Oct 3, 2019

More plugins are popping up

https://conditionalblocks.com

https://blockcontext.com

@jhotadhari
Copy link

jhotadhari commented Aug 14, 2020

Wrote another plugin today. maybe helpful for someone.

Very early development. Not production ready.
Only to condition types by now: true, currentUser.
Condition types are pluggable via js/php filters.

Supports nested conditions.
image

No docs yet.
How to add new condition types? Check implementation for existing type currentUser:

@landwire
Copy link

I wrote a plugin to show/hide Gutenberg Blocks called "Block Logic".
You can find it here:
https://wordpress.org/plugins/block-logic/

It is very flexible and supports hiding/showing of blocks based on all sorts of conditions or functions, even your own function, should you want to write one.

Would be happy if anyone finds it useful!

@paaljoachim
Copy link
Contributor

It is awesome that people post their Conditional plugins here!
Keep it coming!

Here is one more Conditional plugin. This one focused on a show and hide feature.
This one from @ndiego Nick. WPTavern also wrote about it here:
https://wptavern.com/show-and-hide-content-via-the-block-visibility-wordpress-plugin

@ndiego
Copy link
Member

ndiego commented Apr 9, 2021

Thanks for the comment @paaljoachim! Lots of new functionality coming to Block Visibility. If anyone has a feature request, let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] Needs More Info Follow-up required in order to be actionable. [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests