- How do I integrate **twig/inky-extra** into an existing Laravel project with Twig?
- First, install the package via Composer (`composer require twig/inky-extra`). Then, configure a dedicated Twig environment for emails in `config/services.php` and register a service provider to bind it. Use the `inky_to_html` filter in your Twig templates by extending the environment with the Inky extension.
- Can I use **twig/inky-extra** with Laravel’s Mailable classes?
- Yes. Override the `build()` method in your Mailable class to render Twig templates with Inky markup. For example, replace `markdown()` with `$this->twig('emails.welcome.inky.twig', ['user' => $this->user])` and ensure your Twig environment includes the Inky extension.
- What Laravel versions and Twig versions does **twig/inky-extra** support?
- The package requires **Twig 3.x** and works with any Laravel version that supports Twig (Laravel 8+ recommended). Ensure compatibility by checking the package’s dependencies in `composer.json` and verifying your Laravel and Twig versions match the supported ranges.
- How do I handle responsive email design with Inky in Laravel?
- Inky’s markup inherently supports responsive design via media queries. Use Laravel Mix or Vite to inline critical CSS (e.g., `@media` queries) for compatibility with email clients like Gmail. Test responsiveness using tools like Litmus or Email on Acid.
- Does **twig/inky-extra** support reusable email components or partials?
- Yes. Organize your Inky templates in `resources/views/emails/` with `.inky.twig` extensions. Use Twig’s `{% include %}` or `{% extends %}` tags to create reusable components, such as headers, footers, or buttons, while keeping your templates DRY.
- How do I test Inky templates before sending emails in production?
- Render templates locally using `php artisan twig:dump` or a custom helper method. Validate HTML output with Inky’s CLI tools or online validators. Test email rendering in real clients (Gmail, Outlook) using Litmus or Email on Acid to catch rendering issues early.
- Will **twig/inky-extra** work with Laravel’s queue system for transactional emails?
- Absolutely. Offload email rendering by setting `shouldQueue()` in your Mailable class. The `inky_to_html` filter processes templates server-side, so queued jobs will render Inky markup efficiently without blocking HTTP requests.
- Are there alternatives to **twig/inky-extra** for Laravel email templates?
- Alternatives include using Blade templates directly with CSS frameworks like MJML or Foundation for Emails, or leveraging Laravel’s built-in `markdown()` method with HTML email libraries like Mailchimp’s Mandrill. However, **twig/inky-extra** uniquely combines Twig’s flexibility with Inky’s concise, component-based syntax.
- How do I handle dynamic content and security (e.g., XSS) in Inky templates?
- Twig automatically escapes variables by default, mitigating XSS risks. For dynamic content, use Twig’s `{{ variable|raw }}` sparingly and validate inputs. Test edge cases (e.g., HTML/JS in user-provided text) by rendering templates with malicious payloads in a sandboxed environment.
- What’s the best way to maintain and update **twig/inky-extra** in a Laravel project?
- Monitor updates via Packagist or GitHub releases. Use Composer’s `update` command cautiously, as breaking changes may require Twig or Inky version adjustments. Test updates in a staging environment with your email templates to ensure compatibility before deploying to production.