A PHTML formatter restructures PHP-HTML template files with consistent indentation across mixed PHP and HTML content. Used in Magento, WordPress, and classic PHP MVC frameworks, PHTML templates embed PHP control structures directly in HTML markup. This formatter detects <?php ?> blocks and indents the HTML content inside foreach, if, and while loops automatically.
Formatted PHTML will appear here...
Load Example
How to Use the PHTML Formatter
PHTML (PHP + HTML) files are used extensively in Magento storefronts, WordPress themes, and classic PHP MVC frameworks like Laravel Blade's non-Blade equivalent. When PHP control structures mix with HTML markup, the indentation often becomes inconsistent across team edits. A PHTML formatter fixes both the PHP block structure and the HTML indentation simultaneously.
Step 1: Paste Your PHTML File
Copy your .phtml or PHP template file into the input area. The formatter accepts any mix of <?php ?> blocks, <?= ?> short echo tags, and HTML markup.
Step 2: Choose Indentation
Select 2 spaces, 4 spaces, or tabs. Most PHP projects use 4 spaces following PSR-2/PSR-12 coding standards. Click Format PHTML to apply formatting across all sections.
Step 3: Understand PHP Tag Handling
PHP opening control structures <?php if(): ?>, <?php foreach(): ?>, and block openers <?php if (...) { ?> increase indentation for the HTML that follows. Closing keywords <?php endif; ?>, <?php endforeach; ?>, and closing braces <?php } ?> decrease indentation. Short echo tags <?= $var ?> stay inline.
PHTML Template Best Practices
Keep PHTML templates focused on presentation only. Move business logic to controllers or services and pass clean data arrays to the view. Use PHP's alternative syntax (if(): ... endif;) in templates for better readability — it aligns opening and closing keywords visually in the HTML structure, making nested templates easier to follow.
FAQ
Is the PHTML formatter free?
Yes, completely free with no signup required. Format unlimited PHTML template files in your browser.
Is my PHP code safe?
Yes. All formatting runs locally in your browser. Your PHTML templates are never sent to any server.
What PHP syntax does this formatter support in PHTML files?
The formatter handles standard PHP template syntax: <?php ?> full PHP blocks, <?= ?> short echo tags, control structures (if/foreach/for/while/switch), and alternative syntax (if:/endif;, foreach:/endforeach;). PHP control flow blocks increase HTML indentation for the content inside them.
Can I use this for Magento or WordPress templates?
Yes. Magento uses PHTML extensively for frontend templates, and WordPress uses PHP mixed with HTML. The formatter handles both styles and properly indents HTML content inside PHP control structures.
Does the formatter execute PHP code?
No. The formatter only adjusts whitespace and indentation — it never evaluates PHP expressions. Your variables, functions, and logic remain unchanged.
Can I minify PHTML templates?
Yes. The Minify button collapses whitespace while preserving PHP tags and HTML structure, useful for reducing file size before deployment.