PHPackages                             kerrialn/view-converter - 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. kerrialn/view-converter

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

kerrialn/view-converter
=======================

template converter: convert from plain php to twig

v1.2.1(1mo ago)113MITPHPPHP &gt;=7.4

Since Jul 23Pushed 1mo agoCompare

[ Source](https://github.com/Kerrialn/view-converter)[ Packagist](https://packagist.org/packages/kerrialn/view-converter)[ Docs](https://github.com/Kerrialn/view-converter)[ RSS](/packages/kerrialn-view-converter/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (19)Versions (10)Used By (0)

View Converter
==============

[](#view-converter)

Convert legacy PHP view templates to **Twig** or **Blade** syntax, and convert legacy JavaScript files to **Stimulus controllers**, **Vue 3 SFCs**, or modern vanilla JS.

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

[](#installation)

```
composer require kerrialn/view-converter
```

Requirements
------------

[](#requirements)

- PHP &gt;= 7.4
- Node.js &gt;= 16 *(required for `stimulus:convert`, `jquery:convert`, and `vue:convert`)*

---

Commands
--------

[](#commands)

### `convert` — PHP templates → Twig or Blade

[](#convert--php-templates--twig-or-blade)

#### Convert a directory

[](#convert-a-directory)

```
php bin/view-converter convert ./views
```

You will be prompted to choose the output format:

```
Which format would you like to convert TO?
  [twig ] Twig (*.twig)
  [blade] Blade (*.blade.php)

```

#### Convert a single file

[](#convert-a-single-file)

```
php bin/view-converter convert ./views/dashboard.php
```

#### Specify the format directly

[](#specify-the-format-directly)

```
php bin/view-converter convert ./views --format=twig
php bin/view-converter convert ./views --format=blade
```

#### Options

[](#options)

OptionDescription`--format=twig|blade`Output format (prompted if omitted)`--dry-run`Preview the conversion without writing files`--delete-originals`Delete the original `.php` files after conversion---

### `stimulus:convert` — Legacy JS → Stimulus controller

[](#stimulusconvert--legacy-js--stimulus-controller)

Parses a vanilla JavaScript file using an AST parser (Node.js + [acorn](https://github.com/acornjs/acorn)) and generates a [Stimulus](https://stimulus.hotwired.dev/) controller scaffold. Optionally scans your HTML/Twig/Blade templates and reports exactly which `data-` attributes to add to each element.

#### Basic usage

[](#basic-usage)

```
php bin/view-converter stimulus:convert ./js/dropdown.js
```

#### With template scanning

[](#with-template-scanning)

```
php bin/view-converter stimulus:convert ./js/dropdown.js --html-dir=./views
```

#### Preview without writing a file

[](#preview-without-writing-a-file)

```
php bin/view-converter stimulus:convert ./js/dropdown.js --dry-run
```

#### Options

[](#options-1)

OptionDescription`--html-dir=`Directory to scan for HTML/Twig/Blade templates`--name=`Override the generated controller name`--output=`Output directory for the generated controller file (defaults to same directory as the input)`--dry-run`Preview the generated controller without writing a file#### What gets detected

[](#what-gets-detected)

Given a legacy JS file, the converter identifies:

JS patternStimulus output`document.querySelectorAll('.dropdown')`Root element — `data-controller` candidate`el.querySelector('.dropdown-toggle')``static targets = ["toggle"]``el.addEventListener('click', fn)`Action method + `data-action="click->name#method"` suggestion`el.dataset.selectedValue``static values = { selectedValue: String }`Inline handler bodyMigrated verbatim into the method, with TODO comments for anything that needs manual attention`document.addEventListener(...)`Warning issued — flagged as an outside-click pattern requiring manual migration via `connect()`/`disconnect()`#### Example output

[](#example-output)

Input: `dropdown.js`

```
(function () {
    var dropdowns = document.querySelectorAll('.dropdown');
    dropdowns.forEach(function (dropdown) {
        var toggle = dropdown.querySelector('.dropdown-toggle');
        toggle.addEventListener('click', function (event) {
            event.preventDefault();
            // ...
        });
    });
})();
```

Generated: `dropdown-controller.js`

```
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["toggle", "menu", "item", "selected"]

  static values = {
    selectedValue: String,
  }

  connect() {
    // TODO: add any setup that runs when the controller connects to the DOM
  }

  handleToggleClick(event) {
    event.preventDefault();
    // ...
  }

  disconnect() {
    // TODO: remove any document-level listeners that were added in connect()
  }
}
```

Template scan report (when `--html-dir` is used):

```
views/nav.html
  Line 11  Add data-controller="dropdown"
  Line 12  Add data-dropdown-target="toggle"
  Line 12  Add data-action="click->dropdown#handleToggleClick"
  Line 15  Add data-dropdown-target="menu"

```

> **Note:** Node.js dependencies are installed automatically on first run inside the package's `node/` directory — no manual setup required.

---

### `jquery:convert` — Legacy jQuery JS → vanilla JS

[](#jqueryconvert--legacy-jquery-js--vanilla-js)

Rewrites a jQuery-heavy script to modern vanilla JS using an AST parser. Handles the most common jQuery patterns automatically and leaves a TODO comment for anything that needs manual attention.

#### Basic usage

[](#basic-usage-1)

```
php bin/view-converter jquery:convert ./js/modal.js
```

#### Preview without writing a file

[](#preview-without-writing-a-file-1)

```
php bin/view-converter jquery:convert ./js/modal.js --dry-run
```

#### Convert a whole directory

[](#convert-a-whole-directory)

```
php bin/view-converter jquery:convert ./js --output=./js/vanilla
```

#### Options

[](#options-2)

OptionDescription`--output=`Output directory (defaults to same directory as input)`--dry-run`Preview the converted output without writing a file#### What gets converted

[](#what-gets-converted)

jQueryVanilla JS`$(selector)` / `$(el)``document.querySelector` / `document.querySelectorAll``$.ready` / `$(fn)` / `$(document).ready(fn)``document.addEventListener('DOMContentLoaded', fn)``.on('click', fn)``.addEventListener('click', fn)``.on('click keydown', fn)``['click','keydown'].forEach((ev) => el.addEventListener(ev, fn))``.addClass` / `.removeClass` / `.toggleClass``.classList.add` / `.classList.remove` / `.classList.toggle``.hasClass``.classList.contains``.attr(name)` / `.attr(name, val)``.getAttribute` / `.setAttribute``.val()` / `.val(v)``.value` / `.value = v``.text()` / `.html()``.textContent` / `.innerHTML``.hide()` / `.show()``style.display = 'none'` / `style.display = ''``.css(prop, val)``.style.prop = val``.find(sel)``.querySelector(sel)``.closest(sel)``.closest(sel)``.each(fn)``.forEach(fn)``$.ajax` / `$.post` / `$.get` / `$.getJSON``fetch(...)` with chained `.then()``var` declarations`let`jQuery IIFE wrapper `(function($){…})($)`Stripped (body kept)Output files use a `.vanilla.js` suffix.

---

### `vue:convert` — Vanilla JS + HTML template → Vue 3 SFC

[](#vueconvert--vanilla-js--html-template--vue-3-sfc)

Transforms a vanilla JS file (and an optional HTML/PHP/Twig template) into a Vue 3 Single File Component skeleton. Can optionally run the jQuery converter first as part of the pipeline.

#### Basic usage

[](#basic-usage-2)

```
php bin/view-converter vue:convert ./js/modal.js
```

#### With an HTML/PHP template

[](#with-an-htmlphp-template)

```
php bin/view-converter vue:convert ./js/modal.js --html=./views/modal.php
```

#### From jQuery in one step

[](#from-jquery-in-one-step)

```
php bin/view-converter vue:convert ./js/modal.js --from-jquery --html=./views/modal.php
```

#### Preview without writing a file

[](#preview-without-writing-a-file-2)

```
php bin/view-converter vue:convert ./js/modal.js --html=./views/modal.php --dry-run
```

#### Options

[](#options-3)

OptionDescription`--html=`HTML/PHP/Twig template to extract the `` block from`--from-jquery`Run the jQuery converter first, then produce the Vue SFC`--output=`Output directory (defaults to same directory as input)`--dry-run`Preview the generated SFC without writing a file#### What gets converted

[](#what-gets-converted-1)

**JavaScript:**

PatternVue output`document.addEventListener('DOMContentLoaded', fn)``onMounted(fn)``document.getElementById('foo')`Annotated with a `ref` TODO comment; `ref="foo"` injected in template`querySelector` / `querySelectorAll`Annotated with a `ref` TODO commentVue importsCollected and emitted as a single `import { onMounted, ref } from 'vue'` line**PHP/Twig template syntax (when `--html` points to a `.php` or `.twig` file):**

PHPVue template`` / ```{{ var }}````v-if="x"` injected on the next element```v-else-if="x"` injected on the next element```v-else` injected on the next element```v-for="val in arr"` injected on the next element`htmlspecialchars($x)``$x` (Vue auto-escapes)`count($x)``x.length``$arr['key']``arr.key`> Multi-element `v-if` / `v-for` blocks (needing a `` wrapper) and counter-based `for` loops are flagged with a comment for manual migration.

Output files use a `.vue` extension.

---

What gets converted (PHP → Twig)
--------------------------------

[](#what-gets-converted-php--twig)

Uses a full AST parser to accurately convert PHP template logic.

PHPTwig```{{ name }}````{{ items|length }}````{% if active %}````{% for item in items %}````{{ a ~ b }}``isset($x)``x is defined``empty($x)``x is empty``Class::CONST``constant('Class::CONST')`What gets converted (PHP → Blade)
---------------------------------

[](#what-gets-converted-php--blade)

Uses pattern-based conversion to produce Laravel Blade syntax.

PHPBlade```{{ $name }}````{{ $name }}````@if($active)````@elseif($x)````@else````@endif````@foreach($items as $item)````@for($i=0; $i``@php` / `@endphp`License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance92

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~76 days

Total

9

Last Release

38d ago

Major Versions

v0.1.4 → v1.0.02026-05-21

### Community

Maintainers

![](https://www.gravatar.com/avatar/c4eae866619500d24f60960f0ce5a6c67dd3fa4211a463a52c745acfa4b2ace7?d=identicon)[Kerrialn](/maintainers/Kerrialn)

---

Top Contributors

[![Kerrialn](https://avatars.githubusercontent.com/u/41723430?v=4)](https://github.com/Kerrialn "Kerrialn (18 commits)")

---

Tags

phptwigconverterbladetemplatetemplating

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/kerrialn-view-converter/health.svg)

```
[![Health](https://phpackages.com/badges/kerrialn-view-converter/health.svg)](https://phpackages.com/packages/kerrialn-view-converter)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M345](/packages/psalm-plugin-laravel)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

54743.1k4](/packages/jolicode-castor)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9224.3M28](/packages/phparkitect-phparkitect)[rector/rector-src

Instant Upgrade and Automated Refactoring of any PHP code

136406.3k14](/packages/rector-rector-src)[typo3/cms

TYPO3 CMS is a free open source Content Management Framework initially created by Kasper Skaarhoj and licensed under GNU/GPL.

1.2k1.9M122](/packages/typo3-cms)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.1k17.8k](/packages/prestashop-prestashop)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
