Block-Based Themes and the Problem with Dynamic Data in HTML Templates

This post was originally published on this site

The Gutenberg project and its eventual full-site editing feature is coming upon a major issue that will need to be solved. Block-based themes of the future are currently on a path toward a template system that will comprise of plain HTML files. While that will work for the majority of a theme’s output, the trouble is figuring out how the project will handle dynamic values.

Most of the discussion has centered on handling URLs, which are probably the most common use case. Currently, theme templates have all sorts of dynamic content. Much of that will be replaced with blocks as we continue moving toward full-site editing. However, not all dynamic data will have a block equivalent.

A good example is that theme authors cannot currently add the homepage URL to the navigation block. Some experimental block-based themes are using a simple / character, which points to the wrong location on many WordPress installs.

Solving this issue sooner rather than later is important for the progression of theme development in a block world. However, such a solution needs to be carefully crafted so that the theming community is not bogged down by a decade or more with a poor templating implementation.

The Current Proposals

The Gutenberg repository currently has an open ticket for discussion on handling dynamic values in templates. At the moment, there are four proposals on how to address the issue.

On-the-Fly String Replacement

One solution would be to use PHP to parse each HTML file and replace strings representing dynamic data on the fly. This would require parsing all of a theme’s templates on every page load. The downside is that it would slow down the page load. We would need real unit tests to see how much of a spike in loading time this method creates.

Assuming


Continue reading...

Leave a Reply

Your email address will not be published. Required fields are marked *