Currently, we are using our own implementation of columns outside of the core/column. on our side, we have a parent component that uses <InnerBlocks /> with a template that uses our column. The parent block has specific layout options that our column needs to be aware of. For example, if the layout selected is an even 50/50 2 column split, we need to pass that to our columns to show specific options for each column. I've tried adding this to the save function, but it seems like our column is not fully aware of this change happening. Hoping you might have a good sample of code that I could learn from 馃槃
We have just done the exact same thing that you're doing @squibbleFish and came up against this problem.
Our templates were primarily using Columns, with different classes to dictate whether it's:
50 + 50
33 + 33 + 33
25 + 25 +25 + 25
etc.
The primary issue we had was that switching between templates allows us to change between 2 / 3 / 4 columns, but we would end up with something like:
<div class="wp-block-column grid-6"></div>
<div class="wp-block-column grid-6"></div>
<div class="wp-block-column grid-4"></div>
<div class="wp-block-column grid-3"></div>
The template looks to see if the block in position x is in the same place as the new template, but doesn't update the attributes at the same time.
I've just made a PR that resolves this, and are using it in our development environment.
I tried to solve the same task and I ran into a similar problem.
At the first render, all parameters are passed from parent to child successfully and I get the necessary classes in the columns.
However, when the parent is re-rendered (with new params) , the modified parameters are no longer transmitted to child. The child continues to render with the old parameters.
It looks like they are caching somewhere.
For column-style blocks, I've found a better approach is to dispatch events to the nested blocks to change their attributes directly, rather than via the template mechanism.
You can see how we accomplish it in our custom columns block here.
Thank you Chris you made my day.
Indeed, everything is very easily solved and I will go this way.
However, this does not negate the strange and unexpected behavior of templates.
Closing as it appears the reply at https://github.com/WordPress/gutenberg/issues/11873#issuecomment-446010105 solves the issue.
Most helpful comment
For column-style blocks, I've found a better approach is to dispatch events to the nested blocks to change their attributes directly, rather than via the
templatemechanism.You can see how we accomplish it in our custom columns block here.