You are here

Drupal 8 theme suggestion for Commerce product page template per product type

By default you get the following page template suggestions for a Commerce product:

page--product--[ID].html.twig
page--product--%.html.twig
page--product.html.twig
page.html.twig

Here's a template suggestion for custom page templates per product type:

/**
  * Add page templates for Commerce product types
  * Example: page--product--event.html.twig
  */
/**
* Implements hook_theme_suggestions_page_alter().
*/
function THEMENAME_theme_suggestions_page_alter(array &$suggestions, array $variables) {
  if ($product = \Drupal::routeMatch()->getParameter('commerce_product')) {
    $suggestions[] = 'page__product__' . $product->bundle();
  }
}

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.