I'm trying to add inline CSS styles to <head>
section using following PHP code:
$dynamic_style = ".wrapper { width: 90%;} /* This is sample comment */"
drupal_add_css($data = $dynamic_styles, $options['type'] = 'inline', $options['preprocess'] = FALSE);
Unfortunately Drupal ignores anything between /*
and */
. This might look like a minor issue (comments for inline styles are not very useful), but real problems start when I wrap styles with CDATA section:
$dynamic_styles = "<!--/*--><![CDATA[/*><!--*/ .wrapper { width: 100%; } /*]]>*/-->"
drupal_add_css($data = $dynamic_styles, $options['type'] = 'inline', $options['preprocess'] = FALSE);
In this case, the output will be:
<style>
<!-- .wrapper { width: 100%; } -->
</style>
instead of:
<style>
<!--/*--><![CDATA[/*><!--*/ .wrapper { width: 100%; } /*]]>*/-->
</style>
which will result in missing styles and invalid markup.
Documentation says that if 'preprocess' option is set to TRUE, then inline styles "will be compressed when being output on the page". But it appears to me that styles are being compressed no matter whether $options['preprocess']
is set to TRUE or FALSE.