{"id":4466,"date":"2016-08-18T18:56:33","date_gmt":"2016-08-18T23:56:33","guid":{"rendered":"http:\/\/www.carnaghan.com\/?p=4466"},"modified":"2019-09-22T22:24:02","modified_gmt":"2019-09-23T02:24:02","slug":"introduction-drupal-8-theming","status":"publish","type":"post","link":"https:\/\/www.carnaghan.com\/introduction-drupal-8-theming\/","title":{"rendered":"Introduction to Drupal 8 Theming"},"content":{"rendered":"\n
Drupal<\/span> 8 has a new theme<\/span> engine, however many of the concepts we are familiar with in Drupal<\/span> 7 are still in place in this new version<\/span>. Themes<\/span> still have the same ability to overwrite various templates within core, only now instead of modifying<\/span> .tpl.php files<\/span>, you will be creating Twig files<\/span> in their place. Theme functions are still available to use, however they are now kept in the .theme<\/span> file<\/span> instead of template.php. Other changes worthy of exploring in more depth are briefly summarized below.<\/p>\n\n\n\n The biggest change of course has been the move to the Twig Template Engine<\/a>, and I will be getting more into Twig later in this series. For now though, I have been focusing on Day 12<\/a> of the Drupal<\/span> Activity Cards, which introduces us to theming<\/span> at a high level<\/span>.<\/p>\n\n\n\n When looking at the new theme layer in Drupal<\/span> 8, the first thing that stands out as a major integral part of the system is the concept of base themes. Base themes are not new, we have had them in Drupal<\/span> 7 for quite some time, however with Drupal<\/span> 8 pretty much every theme you will use will most likely inherit from two major base themes in the system called Stable and Classy. In fact Bartik and Seven both are sub themes<\/span> of Classy. A Tale of Two Base Themes in Drupal 8 Core<\/a> provides a thorough overview of these new base themes and their importance in Drupal<\/span> 8.<\/p>\n\n\n\n The use of .yml files<\/span> are also prevalent in the new theme<\/span> layer as with other areas in Drupal<\/span> 8, however they more or less simply replace functionality of the previous info and template.php files<\/span> found in Drupal<\/span> 7.<\/p>\n\n\n\n I talked about libraries in Attaching JS and CSS Assets in Drupal<\/span> 8 and they function in a similar with within the theme<\/span> layer itself.<\/p>\n\n\n\n One last major change is the newer integration<\/span> with Drupal<\/span> Console, which lets us generate boilerplate theme<\/span> code, similar to that of custom module<\/span> and content entity<\/span> scaffolding functionality covered in an earlier post.<\/p>\n\n\n\n To get started with theming in Drupal<\/span> 8, you can use the Drupal<\/span> Console to generate starter code by issuing the following command<\/span>:<\/p>\n\n\n\n You will be prompted to provide information for your new theme<\/span> including its name, path, base theme, etc., similar to the screenshot below.<\/p>\n\n\n\nTwig<\/strong><\/h3>\n\n\n\n
Base Themes<\/strong><\/h3>\n\n\n\n
.yml Files<\/strong><\/h3>\n\n\n\n
Libraries<\/strong><\/h3>\n\n\n\n
Drupal<\/span> Console<\/strong><\/h3>\n\n\n\n
Generating your Theme<\/span> via Drupal<\/span> Console<\/h2>\n\n\n\n
drupal generate:theme<\/pre>\n\n\n\n