Update
Edit: RenderWrapper was removed as of #2272279: Kill RenderWrapper class The replacement for calling the functions later is calling them as methods of a class. When printing {{ page.scripts }}
Twig will look for getScripts()
on the page object and when printing will call that method which does what RenderWrapper was doing but with less abstraction.
Original Change record
A RenderWrapper helper class has been added so that function calls can be deferred until they are printed in a template. This new class made it possible to remove the template process layer from the theme system: https://drupal.org/node/2038981.
Before:
function template_process_html(&$variables) {
$variables['scripts'] = drupal_get_js();
}
After:
Preprocess function instead of process function and using RenderWrapper to postpone the call to drupal_get_js().
function template_preprocess_html(&$variables) {
$variables['scripts'] = new RenderWrapper('drupal_get_js');
}
Later preprocess functions must re-wrap the variable in the RenderWrapper if changes are needed, otherwise the variable will be prematurely rendered into a string. Example:
function seven_preprocess_html(&$variables) {
drupal_add_js(drupal_get_path('theme', 'seven') . '/js/mobile.install.js');
$variables['scripts'] = new RenderWrapper('drupal_get_js');
}