I need to customize selected pages in a D7 site so that the DOCTYPE is changed from the RDFa and the default styles/css from Drupal are removed/not loaded -- so html.tpl.php needs to be overridden. I've tried a number of ways all of which have failed. I was able to change the page.tpl.php to use a custom node type for this but I am stymied with html.tpl.php.Any suggestions appreciated.

Comments

jaypan’s picture

What have you done so far? You should only need to copy html.tpl.php to your theme directory and clear the cache.

Contact me to contract me for D7 -> D10/11 migrations.

bobtimms’s picture

Sorry if I wasn't clear. I need the custom html template only on certain nodes. I have been able to set a custom page template for 'page--type--lab.tpl,php' for nodes with content type 'lab'. I need something like an 'html--type--lab.tpl.php for these nodes. I know I can set up using each individual node as in 'html--node--16.tpl.php' but this doesn't make sense with 20 or so nodes for this content type.

jaypan’s picture

Ahh I see what you mean. I've not tried this yet, so I don't have the answer. But did it not work with html--type--lab.tpl.php?

Contact me to contract me for D7 -> D10/11 migrations.

iztok’s picture

Try something like this:

template.php:

function yourthemename_preprocess_html(&$vars) {
  if ($node = menu_get_object()) {
    if($node->type == "lab") {
      $vars['theme_hook_suggestions'][] = 'html__lab';
    }
  }
}

Now copy http://api.drupal.org/api/drupal/modules--system--html.tpl.php/7/source code into html--lab.tpl.php file and modify it. Dont forget to clear cache.

bobtimms’s picture

Awesome! Thank you very much @Iztok. I had been trying to make it work using the array similar to:

function peachfluid_preprocess_html(&$variables) {
if (isset($variables['node'])) {  
    $variables['theme_hook_suggestions'][] = 'html__type__'. $variables['node']->type;
  } 
}

I was able to make the above work for peachfluid_preprocess_page. You saved me much frustration. Thanks again!

dp_warren’s picture

This was really useful and worked perfectly

Thanks bobtimms!

zhongguo999999’s picture

How to set ['node'] properties for $variables['node']?
Thank you!

zenowkc’s picture

I try the last codes by bobtimms, I cannot work? I already change the theme name, and clear the cache, the codes "if (isset($variables['node'])) {  " I try to Echo something, but no message out! what can I do?

globexplorer’s picture

Include the following inside template.php!

function yourtheme_preprocess_html(&$variables) {
  // If on an individual node page, add the node type to body classes.
  if ($node = menu_get_object()) {
    $variables['theme_hook_suggestions'][] = 'html__'. $node->type;
  }
}

Now you can create your html--your_content_type.tpl.php

web226’s picture

Thank you @xvendo your solution worked perfectly for me with Drupal 7.66 & PHP 7.2

victory17’s picture

Thought this might help anyone trying to make custom html.tpl.php by using you path alias. Place this code in your template.php.

function YOURTHEME_preprocess_html (&$vars) {
	if (module_exists('path')) {
    $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
    if ($alias != $_GET['q']) {
      $template_filename = 'html';
      foreach (explode('/', $alias) as $path_part) {
        $template_filename = $template_filename . '__' . $path_part;
        $vars['theme_hook_suggestions'][] = $template_filename;
      }
    }
  }
}
Lakeside’s picture

Thanks Victory17 for posting. Nice piece of code that solved the problem.

deelite’s picture

Hi,

i tryed

function d03_preprocess_html (&$vars) {
  if (module_exists('path')) {
    $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
    if ($alias != $_GET['q']) {
      $template_filename = 'html';
      foreach (explode('/', $alias) as $path_part) {
        $template_filename = $template_filename . '__' . $path_part;
        $vars['theme_hook_suggestions'][] = $template_filename;
      }
    }
  }
}

'd03' is the name of my theme. The path is /go and i named the file html__go,tpl.php.

Cleared the cache.

But is doesn't work...

Can anybody help me please?

deelite’s picture

Oh, i see. I think it's only working for nodes.

Is there a way to get it working for a view?

bevothebun’s picture

Thanks for that code.

I ran into a problem when I had a node named find-a-vet. The '-' character caused a problem, so I modified the above as follows

function YOURTHEME_preprocess_html (&$vars) {	
	if (module_exists('path')) {    
		$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));    
		if ($alias != $_GET['q']) {      
			$template_filename = 'html';      
			foreach (explode('/', $alias) as $path_part) {        
				$template_filename = $template_filename . '__' . str_replace('-','_',$path_part);        
				$vars['theme_hook_suggestions'][] = $template_filename;      
			}    
		}
	}
}

So, for my node, the template file required was html--find-a-vet.tpl.php.

Maybe it is bad practice to have a '-' in an alias, but I thought I would mention it just in case anyone else had the problem.

BadDaddy’s picture

I have tried:

function yourthemename_preprocess_html(&$vars) {
  if ($node = menu_get_object()) {
    if($node->type == "lab") {
      $vars['theme_hook_suggestions'][] = 'html__lab';
    }
  }
}
function yourtheme_preprocess_html(&$variables) {
  // If on an individual node page, add the node type to body classes.
  if ($node = menu_get_object()) {
    $variables['theme_hook_suggestions'][] = 'html__'. $node->type;
  }
}
function YOURTHEME_preprocess_html (&$vars) {
if (module_exists('path')) {
    $alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
    if ($alias != $_GET['q']) {
      $template_filename = 'html';
      foreach (explode('/', $alias) as $path_part) {
        $template_filename = $template_filename . '__' . $path_part;
        $vars['theme_hook_suggestions'][] = $template_filename;
      }
    }
  }
}

...nothing works. Very frustrating! Can anyone please help???

jaypan’s picture

Did you clear your cache after adding each of those?

Contact me to contract me for D7 -> D10/11 migrations.

BadDaddy’s picture

...ok, I have no idea why it suddenly worked. I had been doing the same thing over and over for days with no success, but it just worked out of the blue...very strange. This is the one that finally worked:

Here's a detailed explanation of the steps I went through to make it work:

http://drupal.org/node/1189732

skaught’s picture

function THEME_preprocess_html(&$variables, $hook) {
  $node = menu_get_object();
  if (isset($node)) {  
    $variables['theme_hook_suggestions'][] = 'html__node_'. $node->type;
  }
}
maggros’s picture

Wow - Themeless Nodes looks very useful!
( I am developing on Mac with Acquia Drupal installed; yup -clearing cache with drush after each change; Drupal 7.16)

I have a custom module that does one simple page_callback, like this:
$content = array(
'#markup' => '

.... ... more pretty complex markup....

';
return $content;
- As a drupal page, it renders but the default theme interferes and squidges stuff around.
- That same complex html runs perfectly when simply called to a browser as index.htm

I've tried overriding the default theme with a node.tpl.php and a page.tpl.php
OR is there a way to make Themeless Node work for full page rendering?

with much appreciation for your thoughst on this -

wmkolcz’s picture

I was reading this to see if I can override the html to remove the site's main theme for a section that I was asked to add. Is it possible to override the html.tpl.php for a custom module that has a set of pages