Developer Tip: Set Webforms Template Programmatically

author
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

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
How We Delivered A Market-ready Website With Unified UX In Just 6 Weeks
How We Built An API Developer Portal For a Telecom Giant To Improve Developer Engagement

Let’s start our conversation

  • Business Inquiry
  • Career
  • Others

Business Inquiry

Career

Others