A fix for Drupal 8’s broken preview

Drupal 8 is still beta-ish in so many aspects, that “workarounds” is becoming a separate genre of Drupal development tips and tricks. 

The today’s workaround is for the bug in “node preview” functionality. It is not frequently used, but can be rather convenient for large websites with moderation enabled. The bug can be spotted only when CSS styles, applied to the  node/page template rely on the  <body> CSS classes,  namely the core-added  page-node-type-[node bundle] body class. It helps to effectively distinguish different node templates, and therefore are widely relied on by front-end developers. However, in preview mode, this class appears entirely missing, which breaks the styling.

The workaround is simple and relies on the  hook_preprocess_html() theme hook:

So you can add this hook to you custom module, and solve the problem – and the functionality won’t be broken even after this is fixed in Drupal 8 core.

2 thoughts on “A fix for Drupal 8’s broken preview

Comments are closed.