0

I have a content type called event_page. In event, I have a drop down for selecting templates.

In the templates folder of my active theme, I have included my custom tpl.php files, such as node--event-page--default.tpl.php and node--event-page--blank.tpl.php.

I have used strreplace to remove 'node--event-page--' and '.tpl.php' to populate the types like bank and default from the files in the templates drop down.

Now I am using hook suggestions to take these theme on form submit, but it seems to not working

if (isset($variables['node'])) {
  $node = $variables['node'];
  $field_template_list = $node->field_template_list->und[0]['value'];
  if ($node->type == 'event_page') {
    $variables['theme_hook_suggestions'][] = 'node__event_page__' . $field_template_list;
  }
}

1 Answer 1

1

I hope I understood your question correctly, that you want to apply theme on form submit.

theme_hook_suggestions is used when a template is being rendered. I think you don't need to save it on form submit. You just need to provide logic of selecting a template file in preprocess function of template.php file. Drupal looks for the suggested template file to apply to particular page/node etc

As a pseudo code, it would be

if(template_type is default)
   apply default type
else if(template_type is blank)
   apply blank type

For help, visit this link https://www.drupal.org/node/1089656

Moreover, the example of preprocess function is as follows

function THEME_preprocess_page(&$vars, $hook) {
  if (isset($vars['node']->type)) {
    // If the content type's machine name is "my_machine_name" the file
    // name will be "page--my-machine-name.tpl.php".
    $vars['theme_hook_suggestions'][] = 'page__' . $vars['node']->type;
  }
}
1
  • I am creating a module called event_page. In the node preprocess of the module, I'm doing this, not in the theme's template.php Commented Apr 22, 2015 at 4:09

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.