-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Editor: Experiment with dynamic content as tokens #23268
Conversation
Size Change: +167 B (0%) Total Size: 1.12 MB
ℹ️ View Unchanged
|
This approach doesn't look very promising so I will close this PR. It was nice to go through the process to gather some feedback and see better what kind of challenges we are facing here. I had a quite interesting discussion with @mtias about an alternative approach that we could investigate. I wanted to quickly summarize the idea. There is this
Example usage would be: <data value="token/translation">Cherry Tomato</data> On the server, there would be a logic that parses the output generated and runs filters registered for data tokens: function block_content_token_translation( $content, $value ) {
if ( $value !== 'token/translation' ) {
return $content;
}
return __( $content );
}
add_filter( 'block_content_token', 'block_content_token_translation' ); UI part would work very similar to how other |
Thanks for sharing. This is an interesting idea worth looking into. |
It'd be nice to move this last comment into an issue so that it doesn't get lost. |
Description
Related: #22983.
It's a growing pain in the block editor that we can't embed dynamic data like translations or locally formatted dates. This PR is just an experiment exploring how that interaction could look like using the existing concept of
InnerBlocks
. I don't think it's something that fits for the final implementation because at the moment one block can control only oneInnerBlocks
component.The idea I tried looks as follows:
BlockToken
component that wrapsInnerBlock
to use inedit
method.content
usingRichText
component.render_callback
to dynamically apply translations to the staticcontent
.ServerSideRender
component to dynamically preview content in the editor when the block is not selected.I plan to close this PR at some point. I simply couldn't resist to give it a spin :)
Screenshots
I'm using Polish local for the purpose of this demo to present that translations are applied.
Token block can have some attributes, I integrated a custom class name:
The block toolbar renders in the parent, it has some unnecessary options though that we would have to disable:
Checklist: