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
Closed

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

katerlouis opened this issue Jun 16, 2018 · 5 comments
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@katerlouis
Copy link

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 danielbachhuber added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] Block API API that allows to express the block paradigm. labels Jun 18, 2018
@danielbachhuber
Copy link
Member

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
Copy link

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 Block API: Server-side awareness of block types #2751?
  3. A way to simplify the output of save() - possibly also related to Block API: Server-side awareness of block types #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
Copy link
Author

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
Copy link
Author

katerlouis commented Jun 18, 2018

Similar issues: #5760 #5968 #6239

@mcsf
Copy link
Contributor

mcsf commented Jul 17, 2018

Closing as duplicate of #5760.

@mcsf mcsf closed this as completed Jul 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants