Is there a way to suggest a template in webform 3.x?

I have tried this:

$vars['theme_hook_suggestions'][] = 'webform__form__mywebform';

But it does not work.


3 Answers 3

  1. Apply the latest patch from here: https://www.drupal.org/node/1891220
  2. In your theme's template.php, in YOURTHEME_preprocess_webform_form(), add:

    $path_parts = explode('/', drupal_get_path_alias());

    $path = implode('__', str_replace(array('-', ' ', '+', '.'), '_', $path_parts));

    $hook = $vars['theme_hook_original'];

    $vars['theme_hook_suggestions'][] = "{$hook}__{$path}";


To override the template of webform you just need to name it like :


No need to write the code for this.

  • Yes, but I want to use name not id. Because devel/stagging/production server. I would like to have naming convention.
    – Dawe
    Commented Feb 20, 2015 at 7:29
  • Webform don't have any machine name? How you will differentiate from other webforms? Commented Feb 20, 2015 at 7:37
  • I would like to have it webform-form-[my-own-name].tpl.php
    – Dawe
    Commented Feb 20, 2015 at 7:48
  • How it will be applied to the specific webform? Commented Feb 20, 2015 at 7:50
  • I dont understand you
    – Dawe
    Commented Feb 21, 2015 at 9:59

The reason is this part in webform_theme() function:

'webform_form' => array(
      'render element' => 'form',
      'template' => 'templates/webform-form',
      'pattern' => 'webform_form_[0-9]+',

It will ignore any suggestions if they do not match the pattern. So looks like only webform-form-[nid].tpl.php are working...

What I did (I needed only one special template for some specific webforms), I made a custom numeric suggestion with leading zero (just to be sure it's not NID).

In hook_preprocess_webform_form:

if ($my_custom_conditions) {
 $vars['theme_hook_suggestions'][] = 'webform_form_01';

Drupal does not ignore webform-from-01.tpl.php since it matches the pattern and it won't conflict with other webforms, because of leading zero.

Hope it saves anyone's time :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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