Doesn’t work with themes based on Timber
-
I’m building a new theme based on Timber, a starter theme that allows WordPress template files to be written in Twig.
Timber handles output in a weird way. It gathers up all the data that might be rendered in a Twig template into a
$context
variable, then it uses PHP’sob
functions to capture output, then it renders the Twig templates, passing$context
to them. Finally, it flushes PHP’s output buffer to actually emit the pages.The trouble is that it populates the
$context
variable with everything, including sidebar content, before it attempts to render any output, and, in particular, before it callswp_head()
. Since this plugin does its work in head, as opposed to filters called bydynamic_sidebar()
, it doesn’t get triggered until long after Timber-based themes have captured the output of the sidebars.Long term I’d like to suggest that this plugin do it’s work during the processing of
dynamic_sidebar()
vs.wp_head()
, so that the work is done at the time that it’s needed. It is not a best practice to assume that actions are performed in a particular order.Short term, do you have any suggestions as to how to use this plugin in themes based on Timber? I could code something completely hack-ish in my theme, like
if ( class_exists( 'CustomSidebarsReplacer' ) ) CustomSidebarsReplacer::instance()->replace_sidebars();
but oy, that’s ugly, hack-ish and brittle. Any other thoughts on how I can use this plugin as is?
- The topic ‘Doesn’t work with themes based on Timber’ is closed to new replies.