Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 291122

Refactor template_preprocess()

$
0
0

As originally proposed in #306358-10: Add $classes to templates with new theme_process_hook functions, the function template_preprocess() adds in some arbitrary variables for every template. Many of these are superfluous and are simply "nice-to-haves" that tend to create messy markup or involves an extra layer of processing (such as hook_template_preprocess_default_variables_alter()).

With the move to Twig, there are also unintended consequences. For example:

<?php
 
// Initialize html class attribute for the current hook.
 
$variables['attributes']['class'][] = drupal_html_class($hook);
?>

In PHP template, we had control of whether we printed the classes or not. However, with the Attribute object, this will *always* insert a class based on the hook name when we use the following Twig syntax:

  <div{{ attributes }}>

For themers defining their own theme hooks, this could be annoying. I'd advise we do not need a HTML class name for every single template, and that this could take place on a case-by-case basis via template_preprocess_HOOK() when necessary.


Viewing all articles
Browse latest Browse all 291122

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>