Because in the Drupal 7 Commerce module, the fields, 'sku,' 'title,' and 'status' aren't editable by Display Suite field wrappers, I'm unable to edit the field wrapper via the Drupal front end, I need to use a template to update "commerce-product-title.tpl.php" with an H2 wrapper, but I only need this for the 'product_full' view mode on all products. Is there a way to target this field in this display mode only with a template or theme function?


1 Answer 1



You have to add the theme hook suggestion yourself, first. For fields it's just the same as for nodes. Simply place the following snippet in your theme's template.php or your module's *.module file and replace MYTHEME/MYMODULE with your theme's or module's machine name.

Now copy the /modules/field/theme/field.tpl.php file over to your theme's /templates directory and name it along one of the following patterns:

  • field--field-name--view-mode.tpl.php
  • field--field-name--bundle--view-mode.tpl.php

 * Implements hook_preprocess_HOOK().
function MYTHEME/MYMODULE_preprocess_field(&$variables) {

  $view_mode = $variables['element']['#view_mode'];
  $field_name = $variables['element']['#field_name'];
  $bundle = $variables['element']['#bundle'];

  $variables['theme_hook_suggestions'][] = 'field__' . $field_name . '__' . $view_mode;
  $variables['theme_hook_suggestions'][] = 'field__' . $field_name . '__' . $bundle . '__' . $view_mode;

Commerce Product title

For Commerce' product titles though things are a little bit different, as you don't get the view mode or the referencing entity from within its preprocess hook. But you can simply use your own logic to add your template suggestions. For example a pattern in the URL alias or something like that.

Then copy the /sites/all/modules/contrib/commerce/modules/product/theme/commerce-product-title.tpl.php file over to you theme's /templates directory and rename it along your desired pattern.

  • commerce-product-title--foo.tpl.php

 * Implements hook_preprocess_HOOK().
function MYTHEME/MYMODULE_preprocess_commerce_product_title(&$variables) {

  // The following suggestion only gets added when there's
  // a certain keyword at the third position in the URL alias
  // as in /myproducts/overview/foo/myproduct.
  if (arg(2, drupal_get_path_alias()) === 'foo') {
    $variables['theme_hook_suggestions'][] = $variables['theme_hook_original'] . '__' . 'foo';

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.