1

How can I create a clean theming markup so that the output uses the same indented structure as in my static html template? E.g. when I insert $head; Drupal uses it’s indenting format.

How can I control the ouput?

snippet from the html.tpl.php

<head>

  <title><?php print $head_title; ?></title>
  <?php print $head; ?>
  <?php print $styles; ?>

</head>

The output looks like this

<head>

  <title>Lorem Ipsum | mothership</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Generator" content="Drupal Mothership" />
<link rel="canonical" href="/d7-demo/node/1" />
<link rel="shortlink" href="/d7-demo/node/1" />
  <style media="screen">
@import url("http://localhost/d7-demo/modules/shortcut/shortcut.css?nmdogy");
@import url("http://localhost/d7-demo/modules/toolbar/toolbar.css?nmdogy");
@import url("http://localhost/d7-demo/sites/all/themes/mothership/mothership/css/mothership.css?nmdogy");
@import url("http://localhost/d7-demo/sites/all/themes/itsgoodtobehere/bootstrap/css/bootstrap.min.css?nmdogy");
</style>

</head>

instead of

<head>

  <title>Lorem Ipsum | mothership</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="Generator" content="Drupal Mothership" />
  <link rel="canonical" href="/d7-demo/node/1" />
  <link rel="shortlink" href="/d7-demo/node/1" />
  <style media="screen">
    @import url("http://localhost/d7-demo/modules/shortcut/shortcut.css?nmdogy");
    @import url("http://localhost/d7-demo/modules/toolbar/toolbar.css?nmdogy");
    @import url("http://localhost/d7-demo/sites/all/themes/mothership/mothership/css/mothership.css?nmdogy");
  </style>

</head>
6
  • 2
    The important question is: why would you care? What benefits are you hoping to gain by adding a few more bytes to the size of your html? Arguably your html should actually be minified anyway in this day and age
    – Clive
    Apr 6 '15 at 11:48
  • How do you expect Drupal to auto indent it?
    – AKS
    Apr 6 '15 at 12:45
  • Why? Due to the fact I do care about it! As shown above Drupal should auto-indent the code <?php print $head; ?> with 2 tab stops below <title><?php print $head_title; ?></title>.
    – howdytom
    Apr 6 '15 at 13:03
  • Nope, Drupal shouldn't auto-indent the code; there's no technical or standards-based reason for it to do so. It makes absolutely no difference to anyone, man or machine. If you're hell bent on making this happen it's possible: you'll need to implement hook_element_info_alter(), replace the #pre_render callback for the 'styles' element with your own. That callback will need to be a re-implementation of drupal_pre_render_styles() that formats the @import statements to your requirements
    – Clive
    Apr 6 '15 at 15:16
  • You could maybe look to override theme_html_tag() to make the rest of the tags line up
    – Clive
    Apr 6 '15 at 15:18
0

HTML Tidy can do what you're wanting, but this is designed as text format, Configuration » Content authoring » Text formats which are used in fields rather than the whole site.

Is should be possible with some work to pass the entire theme though HTML Tidy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.