Blogs | Srijan

Developer Tip: Set Webforms Template Programmatically

Written by Team Srijan | Oct 15, 2015 7:00:00 AM

This developer tip will help you assign a particular theme for a set of specific webforms.

function MYMODULE_theme($existing, $type, $theme, $path) {
  $webform = array();
  $webform_info = variable_get('MYMODULE_webform_info', array());
  foreach($webform_info as $nid => $data  ) {
    $webform['webform_form_' . $nid] = array(
      'render element' => 'form',
      'template' => 'webform-form-ispace',
      'path' => drupal_get_path('theme', 'MYTHEME') . '/templates',
      'pattern' => 'webform_form_[0-9]+',
    );
  }
  return $webform;
} 
Note: $webform_info = variable_get(‘MYMODULE_webform_info’, array());

 

 

Here we get the list of webforms which needs to have template set.

Template file webform-form-ispace.tpl.php should be placed under the templates folder in the selected theme.