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.
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.
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 :
webform-form-[nid].tpl.php
No need to write the code for this.
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 :)