PHPackages                             repinspl/php-cs-fixer-html-indent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. repinspl/php-cs-fixer-html-indent

ActiveLibrary[Templating &amp; Views](/categories/templating)

repinspl/php-cs-fixer-html-indent
=================================

PHP-CS-Fixer custom fixers that preserve HTML-context indentation in mixed PHP/HTML files

v0.1.1(2mo ago)317MITPHPPHP &gt;=8.0

Since Feb 27Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/RepinsPL/php-cs-fixer-html-indent)[ Packagist](https://packagist.org/packages/repinspl/php-cs-fixer-html-indent)[ RSS](/packages/repinspl-php-cs-fixer-html-indent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

PHP-CS-Fixer HTML Indent
========================

[](#php-cs-fixer-html-indent)

Custom fixers for [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) that preserve indentation of PHP blocks embedded in HTML/Blade files.

The problem
-----------

[](#the-problem)

PHP-CS-Fixer formats PHP blocks without considering the surrounding HTML context. In mixed files (e.g. Blade templates) this breaks the indentation:

**Before running php-cs-fixer** — correct indentation within the HTML context:

```

		where('active', true)
				->get();

			foreach ($users as $user) {
				echo $user->name;
			}
		?>

```

**After running php-cs-fixer** — HTML context indentation is lost:

```

		where('active', true)
    ->get();

foreach ($users as $user) {
    echo $user->name;
}
		?>

```

**With this library** — php-cs-fixer formats the PHP while the HTML indentation is preserved:

```

		where('active', true)
				->get();

			foreach ($users as $user) {
				echo $user->name;
			}
		?>

```

Installation
------------

[](#installation)

```
composer require --dev repinspl/php-cs-fixer-html-indent
```

Configuration
-------------

[](#configuration)

Register both fixers and enable their rules in your `.php-cs-fixer.dist.php`:

```
