Creating a server-side rendering block that leverages an existing shortcode
As mentioned at the start of this chapter, block creation uses a different programming pipeline by leaning more heavily on JavaScript. This means that providing a simple block to complement an existing simple shortcode, as we've done in this chapter's first recipe, results in code duplication in our plugin. It's also not always easy for developers who are more accustomed to PHP and HTML to create complex blocks using pure JavaScript code. To alleviate these issues, WordPress offers a method by which plugins can use a server-side PHP function to render a block's content. This allows developers to offer plugins with shortcodes and blocks that share the same code base.
Getting ready
You should have already followed the Creating a new WordPress REST endpoint recipe to have a starting point for this recipe. The resulting plugin should still be active on your development site. Alternatively...