Different Code Styles for PHP and HTML-Templates containing PHP

Hey,

i usually use 4 indents for my PHP files and 2 indents for my HTML. The HTML-Templates contain PHP-Snippets as well and thus have a .php file name ending as well.

Now I've got the problem that my files are always recognized as PHP and get the 4 indents when I reformat the code. Is it possible to treat my HTML-Templates correctly as HTML so they get formated correctly?

6 comments
Comment actions Permalink

Hi there,

AFAIK in order to have your php+html templates to be treated as html (in terms of code style) you have to associate it with "HTML files" file type where you will loose your PHP functionality.

The only thing I may think of right now is to get EditorConfig plugin and configure .editorconfig file with specific settings (you use separate file extension for such PHP+HTML files -- usually it's *.phtml) -- settings from such file will override your Code Style. Have not tried myself (how it's implemented in PhpStorm/that plugin) but worth checking out.

0
Comment actions Permalink

I would also appreciate the ability to set the code style for .php and .phtml files independently.

0
Comment actions Permalink

@Robert Sipek

Next version (2019.2) can read whole Code Style settings from EditorConfig files.

You may export your settings there and then manually configure it to have different ones for *.phtml files (or whatever you need) -- AFAIK IDE should support this (it does for standard settings like trimming whitespace at the end of the line etc).

Check 2019.2 EAP build -- see this blog post for more info and links: https://blog.jetbrains.com/phpstorm/2019/06/phpstorm-2019-2-eap-192-5118-33/

1
Comment actions Permalink

The EditorConfig file is the solution. Thanks.

0
Comment actions Permalink

@Robert Sipek

Since you were after different indents ... the EditorConfig approach will work even now (my first message here is from July 2017 and it worked fine back then).

Just from next 2019.2 version the plugin will be bundled by default (so no manual install is required) and you will be able to control all bits of Code Style, not just  standard EditorConfig settings (which are just a general settings: https://editorconfig.org/#file-format-details ).

0

Please sign in to leave a comment.