Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use different node templates if the url is appended with ?template=x

Content type is called image

Default Node template using node--image.tpl.php:

  • blakedesign.co.nz/testsite/node/1

Same node with different template via URL possibly node--image--templateX.tpl.php:

  • blakedesign.co.nz/testsite/node/1?template=2
  • blakedesign.co.nz/testsite/node/1?template=3
  • blakedesign.co.nz/testsite/node/1?template=4

How do i go about doing this?

I have made an example at http://blakedesign.co.nz/testsite/node/1

share|improve this question
up vote 3 down vote accepted

You can create custom template suggestions for node using hook_preprocess_node... In your case it should be below code in your theme template.php file... You can read query arguments using $_GET variable..

function YOURTHEME_preprocess_node(&$variables) {
  if ($variables['type'] == "image" && isset($_GET['template'])) {
    $variables['theme_hook_suggestion'] = 'node__image__template' . $_GET['template'];

Your template file should be...



node--image--template3.tpl.php etc...
share|improve this answer
Works like a charm. Changed if ($variables['type'] == "image" && $_GET['template']) { to if ($variables['type'] == "image" && isset($_GET['template'])) { – blakedesign May 9 '14 at 3:18
shouldn't it would be better if we use $variables['theme_hook_suggestion'][] – Human Love May 11 '14 at 15:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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