Developer Tip: Set Webforms Template Programmatically

By Team Srijan Oct 15, 2015

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.

Shared Success

Building a Drupal-based content collaboration tool
How We Helped a Leading Biopharma Company Streamline their Publishing Cycle with a Drupal CMS
How We Helped 8world Deliver New Digital Experiences Through A Hybrid CMS
How We Helped A Telecom Giant Shorten The Time-To-Market For APIs

Let’s start our conversation

  • Business Inquiry
  • Career
  • Others

Business Inquiry