-
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
Add dynamic block documentation #4067
Conversation
docs/blocks-dynamic.md
Outdated
@@ -0,0 +1,77 @@ | |||
It is also possible to create dynamic blocks. These are blocks that can change their content even if the post is not saved. One example from WordPress itself is the latest posts block. This block will update everywhere it is used whena new post is published. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a "title" for the page.
"It is also possible ..." suggest that we read something before. Is this the case? or should we drop "also"
"whena" should be "when a"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small comments, but thanks for adding this. I also had some people asking about it.
docs/blocks-dynamic.md
Outdated
|
||
The following code example shows how to create the latest post block dynamic block. | ||
|
||
```js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per consistency with other docs, should we include ES5 and ESNext varieties here?
docs/blocks-dynamic.md
Outdated
registerBlockType = wp.blocks.registerBlockType, | ||
withAPIData = wp.components.withAPIData; | ||
|
||
registerBlockType( 'riad/latest-post', { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per consistency with other docs, should we use a more generic namespace here, since without context of blog it's sourced from, unclear what Riad's name is doing here 😄 Other places we're using my-plugin
.
docs/blocks-dynamic.md
Outdated
<?php | ||
// block.php | ||
|
||
function riad_render_block_latest_post( $attribites ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More Riad 😄 (and below in register_block_type
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't be jealous :P
|
||
* The edit function still shows a representation of the block in the editor's context (this could be very different from the rendered version, it's up to the block's author) | ||
* The save function just returns null because the rendering is performed server-side. | ||
* The server-side rendering is a function taking the block attributes as an argument and returning the markup (quite similar to shortcodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to be clearer about how attributes are also defined on the server for this to work correctly? Though in this case there are no attributes for this block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, I've copied these points from Riad's post. Could we merge this and iterate on it further?
docs/blocks-dynamic.md
Outdated
<?php | ||
// block.php | ||
|
||
function my_plugin_render_block_latest_post( $attribites ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: $attribites
-> $attributes
Should we omit this if it's an unused variable?
I wanted to onboard one of our developers onto writing a dynamic Gutenberg block, but I couldn't find the documentation. So I've added the documentation from @youknowriad's blog to the handbook. Taken from https://riad.blog/2017/10/16/one-thousand-and-one-way-to-extend-gutenberg-today/#dynamic-block. I've rewritten some sentences to better fit the handbook.