evo-mark / inertia-symfony
Inertia.js adapter for Symfony
Package info
github.com/evo-mark/inertia-symfony
Type:symfony-bundle
pkg:composer/evo-mark/inertia-symfony
Requires
- php: >=8.4
- ext-curl: *
- ext-json: *
- symfony/clock: ^8.1
- symfony/console: ^8.1.5
- symfony/dependency-injection: ^8.1
- symfony/filesystem: ^8.1
- symfony/framework-bundle: ^8.1
- symfony/http-client: ^8.1
- symfony/http-foundation: ^8.1
- symfony/http-kernel: ^8.1
- symfony/process: ^8.1
- symfony/twig-bundle: ^8.1
- twig/twig: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.95
- phpunit/phpunit: ^13.0
- symfony/browser-kit: ^8.1
- symfony/error-handler: ^8.1.5
- symfony/mime: ^8.1
- symfony/serializer: ^8.1
- symfony/validator: ^8.1
Suggests
- symfony/validator: Send #[MapRequestPayload] validation errors back to Inertia forms
Provides
None
Conflicts
None
Replaces
None
README
evo-mark/inertia-symfony
A Symfony bundle for building Inertia.js applications, including server-side rendering (SSR).
Requires PHP 8.4+ and Symfony 8.
Installation
Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.
Applications that use Symfony Flex
Open a command console, enter your project directory and run:
composer require evo-mark/inertia-symfony
Applications that don't use Symfony Flex
Step 1: Download the bundle
Open a command console, enter your project directory and run this command to download the latest stable version of the bundle:
composer require evo-mark/inertia-symfony
Step 2: Enable the bundle
Enable the bundle by adding it to the list of registered bundles in your project's
config/bundles.php file:
// config/bundles.php return [ // ... EvoMark\InertiaSymfonyBundle\EvoMarkInertiaSymfonyBundle::class => ['all' => true], ];
Then set up the frontend and the root template: see Getting started.
Usage
Render a page from a controller by injecting InertiaInterface:
use EvoMark\InertiaSymfonyBundle\Interfaces\InertiaInterface; use Symfony\Component\Routing\Attribute\Route; class HomeController { #[Route('/', name: 'home')] public function __invoke(InertiaInterface $inertia) { return $inertia->render('Home', ['title' => 'Welcome']); } }
Create the root template with bin/console inertia:view (add --force to
overwrite). It is named after the root_view setting, app.html.twig by default,
and outputs the page with
the inertiaHead() and inertiaApp() Twig functions:
<head> {{ inertiaHead(page) }} </head> <body> {{ inertiaApp(page) }} </body>
Configuration
Settings live under evo_mark_inertia_symfony in config/packages/evo_mark_inertia_symfony.yaml.
All of them are optional:
evo_mark_inertia_symfony: root_view: app.html.twig ssr: enabled: false url: http://127.0.0.1:13714 throw_on_error: false
Run bin/console config:dump-reference evo_mark_inertia_symfony to see every option.
Testing
composer test
Licence
Released under the MIT licence.