15

Does anyone know of a way to instruct PHPStorm to treat Craft templates as Twig files, without globally assigning all .html files to be interpreted as Twig? Since Craft templates don't use the .twig extension, PHPStorm thinks they're HTML.

On that note, why doesn't Craft use .twig extensions? I assume P&T doesn't want to scare away users who are comfortable with HTML but not Twig?

Garrett
  • 417
  • 3
  • 10

3 Answers3

15

Under the PhpStorm preferences, go Editor->File Types->Twig and add *.html as a Registered Pattern.enter image description here

Brad Bell
  • 67,440
  • 6
  • 73
  • 143
  • Yea, I was hoping there was some way to do it w/o globally interpreting .html as Twig. I guess there's no downside, other than it just feels wrong. – Garrett Jun 15 '15 at 15:31
  • 2
    The only problem with this is that it re-assigns it from HTML files. So when you use html files again in another project you will have to switch it back. FYI. – mattl Jul 19 '15 at 19:21
  • 1
    You can solve this by adding *?html as a filetype. That way, everything that ends with .html will also get syntax highlighting without breaking regular html support. – Bert H Apr 02 '19 at 07:04
4

Even easier way… Just add .html.twig to defaultTemplateExtensions and update your template file extension to .html.twig. PHPStorm will pick up both html and twig syntax highlighting.

<?php

/**
 * General Configuration
 *
 * All of your system's general configuration settings go in here.
 * You can see a list of the default settings in craft/app/etc/config/defaults/general.php
 */

return array(
    'defaultTemplateExtensions' => array('html.twig', 'html'),
);
Leevi Graham
  • 433
  • 2
  • 6
2

Instead of adding *.html as a registered Twig patter, I use *?html. Seems to work just fine and I don't have to switch back and forth.

On the flip side, Twig support in PhpStorm seems to contain all the HTML support as well, so other than feeling wrong (which it does), there may be no downside to just switching it over to Twig.

mcmurphy
  • 121
  • 4