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

Partial dynamic block rendering / Static content in dynamic blocks #7331

Closed
katerlouis opened this issue Jun 16, 2018 · 5 comments

Comments

@katerlouis
Copy link

@katerlouis katerlouis commented Jun 16, 2018

In the examples you return null; in save() for dynamic blocks.
But what if I only want parts of my block to be dynamic and others to be static?

What happens to saved content, when a block gets rendered dynamically with PHP?

I imagine something like this:
$savedHTML as a parameter

// plugins/myBlock/index.php
add_action("init", function() {

    wp_register_script( ... );
    wp_register_stlye( ... );

    register_block_type( 'rene-blocks/test', array(
        'editor_script' => 'myScript',
        'editor_style' => 'myStyle',

        'render_callback' => function( $attributes, $savedHTML ) {
        	// create html with $attributes and mix in $savedHTML as I please
        }

    ) );
})
@katerlouis katerlouis changed the title Partial dynamic block rendering Partial dynamic block rendering / Static content in dynamic blocks Jun 16, 2018
@danielbachhuber

This comment has been minimized.

Copy link
Member

@danielbachhuber danielbachhuber commented Jun 18, 2018

But what if I only want parts of my block to be dynamic and others to be static?

Can you clarify what you're trying to accomplish with this use case?

@nyordanov

This comment has been minimized.

Copy link

@nyordanov nyordanov commented Jun 18, 2018

@danielbachhuber I found this issue yesterday while toying with some ideas. Example use cases:

  1. Static "author bio" block, which displays the latest post by the author.
  2. A block which is saved as static, but its template is modified based on whether another plugin is active. Think of this as a per-block filter in do_blocks(). Maybe this is addressed by #2751?
  3. A way to simplify the output of save() - possibly also related to #2751? Maybe used as a fallback when the plugin implementing a dynamic block is deactivated.

A related problem is that editing dynamic modules in the Code Editor in hard. This is just five lines in a RichText:

<!-- wp:nyordanov/test {"text":[{"type":"p","key":"_domReact3","ref":null,"props":{"children":"RichText"},"_owner":null},{"type":"p","key":"_domReact5","ref":null,"props":{"children":["is ",{"type":"strong","key":"_domReact9","ref":null,"props":{"children":"hard"},"_owner":null}," to"]},"_owner":null},{"type":"p","key":"_domReact13","ref":null,"props":{"children":"edit"},"_owner":null},{"type":"p","key":"_domReact16","ref":null,"props":{"children":"in the"},"_owner":null},{"type":"p","key":"_domReact19","ref":null,"props":{"children":"Code Editor"},"_owner":null}]} /-->
@katerlouis

This comment has been minimized.

Copy link
Author

@katerlouis katerlouis commented Jun 18, 2018

I wanted to use a mix of static and dynamic output as a workaround, since I am not able yet to output <RichText> properly #7332

So I figured: Why not save the paragraph statically, and add the gallery stuff on top dynamically in php.

Another possible use-case:
I am extending a block but don't want to recreate all it's logic and html output in PHP. This can be very tedious for complex blocks. All I have to do now is add my own attribute and, make my own dynamic rendering logic, and add the saved html.

You could always argue everything is possible with both methods, so just pick one for the entire block. But as I see Gutenberg, it lives and breathes: I want to make working with content more convenient and give options to both editors and developers.

Maybe I'm missing something here, but to me not having access to what has been saved statically in php is a wasted potential.

@katerlouis

This comment has been minimized.

Copy link
Author

@katerlouis katerlouis commented Jun 18, 2018

Similar issues: #5760 #5968 #6239

@mcsf

This comment has been minimized.

Copy link
Contributor

@mcsf mcsf commented Jul 17, 2018

Closing as duplicate of #5760.

@mcsf mcsf closed this Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.