Skip to main content

Override html.tpl.php for a certain content type

Override html.tpl.php for a certain content type

Similar to another post aimed at using a different page.tpl.php for a certain content type, sometimes I've needed to call in the node via an iframe or similar, so I really need a different html.tpl.php for a certain content type...

I've laid the content out in a similar way to the other post...

  • For starters, lets use some example names/variables, lets say:
  • The theme I’m using is called ‘myTheme’
  • The ‘content type’ I have set-up is called ‘News Article’
  • The ‘machine name’ for my ‘content type’ is ‘news_article’

Solution

  • After you have created your content type (i.e. ‘News Article’)…
  • Copy your html.tpl.php page and rename it ‘html--’ + ‘machine name for your content type’ + ‘.tpl.php
  • So if the ‘machine name’ for my ‘content type’ was ‘news_article’, my file would be ‘html--news-article.tpl.php’
  • Note: the underscore has been changed for a hyphen.
  • Open your template.php file and add the following code
function myTheme_preprocess_html(&$vars) { 

	$node = menu_get_object();
	
	if ($node && $node->nid) {
		$vars['theme_hook_suggestions'][] = 'html__' . $node->type;
	}
	
}
Related Articles
  • Override page.tpl.php for a certain content type
  •  
Main Category
  • Drupal 7
  •  
Secondary Categories
  • Drupal
  •  
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • CodeIgniter
    • Handy Functions
    • MySQL
  • WordPress
  • About

BBC Technology News

  • General election 2019: Reddit says UK-US trade talks document leak 'linked to Russia'
  • 'How smart home tech helps me live independently'
  • NHS e-health systems 'risk patient safety'
  • General election 2019: Labour pledges to electrify UK bus fleet
  • Sweden's Ericsson to pay over $1bn to settle US corruption probe
More

Sitepoint

  • The Real Future of Remote Work is Asynchronous
  • 7 Ways Developers Can Contribute to Climate Action
  • How to Divert Traffic Using IP2Location in a Next.js Website
  • 10 Zsh Tips & Tricks: Configuration, Customization & Usage
  • Building a Habit Tracker with Prisma, Chakra UI, and React
More

Heart Internet

  • Sponsor Neil Hunter’s amazing Antarctic expedition – for Diabetes UK
  • 15 web design books of 2019 that you should read
  • 12 podcasts for every creative person’s commute
  • Ten TED Talks every designer and web creative should watch before 2019 is over
  • The rise of the robots: Will AI take over graphic design?
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
 

© Jon Moore 2019

All stock images are from www.istockphoto.com