PHP Code Style In .htm File In PhpStorm
If I add some php code to a .html
or .htm
file in PhpStorm, the code style for that bit of php code is NOT the same as in .php
file.
For instance, here is the same code in two different file formats:
How can I get the php code segment inside of the .htm
to look like it does in a .php
file?
UPDATE
The reason I want php code styling within an htm file is because I am using October CMS. October CMS uses a .htm file extension which is divided into three section. One of those section is for php code. What I want to know is how can I get the php content code which resides in the htm file to use my php code styles within PhpStorm.
Answer
In order for PhpStorm to recognize and highlight PHP code in any file such file MUST be associated with "PHP File" file type and have PHP icon next to file name.
By default .htm
/.html
files are associated with "HTML Files" file type.
Few possible solutions:
- Change extension of existing file to be
.php
- Use
.phtml
file extension -- which is commonly used extension for such cases (in general denotes that this file is a "template" -- a HTML file mixed with PHP instructions) Associate
.htm
(or whatever else extension you want) with "PHP File" file type.For that:
Settings/Preferences | Editor | File Types
-- find "PHP File" and add appropriate pattern (e.g.*.htm
). IDE will ask if you want to remove such pattern from existing/default "HTML File" to this "PHP File".Possible downside: some HTML inspections may not be triggered (relaxed) in PHP file.
NOTE: Such association is IDE-wide and affects ALL projects.
The best/most neutral solution overall is #2 -- use dedicated file extension for such files (*.phtml
is a most commonly used).
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?