I am still adjusting to the paradigm shift to Block Themes after being away from WordPress for some time. I understand the practical reasons for many aspects of the Block Theme, and for the shift to static pages, in particular. That said, it's really sort of killing my development workflow. For example, I have a template (.html) for a custom home page. In this template, I have a custom pattern (.php) that will runs a query and prints out some stuff about the posts. I create a new page in the admin panel and use this new, partially-finished page template and all the test output from the pattern looks good. But if I then modify the logic/output in the pattern file and refresh the page, it is not updated: the page was contains the static output rendered from the pattern when the page was created.
I understand that the above is to be expected. I have also seen it recommended to use a dynamic block (https://developer.wordpress.org/block-editor/how-to-guides/block-tutorial/creating-dynamic-blocks), however, this sort of trips me up because it is a mix of JavaScript (can't tell at first glace if it's intended to be run client-side or server-side) and PHP. Of course, historically, most aspects of the page would be generated dynamically, server-side on page request.
I guess my question is really how would you develop a pattern like this? Note that I do not intend to publish this theme: it is for use by a single client. Also, the pattern does not need to be editable or even viewable on the admin panel. The only requirement is that it pulls a certain number of posts based on predetermined criteria and does some stuff with the results. During development however, I would like to be able to make some changes in my text editor (not the admin editor), refresh the page, and see the updates.
Edit
One way I've found around this is,
- Create page template as described
- Create page
- When prompted to select a page template, cancel the dialogue
- Simply name the page and select the new page template from the select menu on the right
After save, the page will not show any content in the editor. However, on the front end, the page will be rendered dynamically as is typical of a PHP-driven website.
All that said, I would like to understand more how others are tackling development of dynamic blocks. I did find the following resources, which seem very promising,
- https://kinsta.com/blog/dynamic-blocks/
- https://kinsta.com/blog/gutenberg-blocks/#what-is-a-gutenberg-block
For now, and as mentioned, because this is a single-use theme and not intended for distribution, I will continue for now using the described workaround.