- How do I install twig/cssinliner-extra in a Laravel project using Twig?
- Run `composer require twig/cssinliner-extra` in your project directory. Then register the extension in your Twig configuration (e.g., `config/twig.php`) by adding it to the `extensions` array. No additional Laravel-specific setup is required beyond Twig’s standard extension registration.
- Can I use this package with Laravel Blade templates?
- No, this package only works with Twig templates. Laravel Blade uses a different syntax and templating engine, so you’ll need alternatives like Premailer or MJML for Blade-based email projects. Workarounds (e.g., pre-processing Blade to Twig) are unsupported and not recommended.
- What Laravel versions does twig/cssinliner-extra support?
- The package itself doesn’t enforce Laravel version constraints, but it requires Twig 1.x or 2.x. Ensure your Laravel project’s Twig version is compatible (e.g., Laravel 8+ uses Twig 2.x). Check the package’s `composer.json` for Twig version requirements and align your Laravel setup accordingly.
- Does this package support complex CSS selectors like @media queries or :hover?
- No, the package silently drops unsupported CSS features like `@media`, `:hover`, and complex selectors. For advanced email designs, you’ll need to manually inline these styles or redesign templates to avoid them. Test thoroughly in email clients like Outlook or Gmail to catch missing styles.
- How do I apply the inline_css filter in a Twig email template?
- Use the filter directly in your Twig template like this: `{{ content|inline_css }}`. This processes the HTML and converts embedded or external CSS into inline `style` attributes. For example, include a Twig partial with CSS and apply the filter to the rendered output before sending the email.
- Is this package safe for production use? Are there security risks?
- The package is generally safe if configured correctly, but fetching external CSS (`remote: true`) introduces XSS risks. Always sanitize inputs and disable `remote` unless absolutely necessary. For production, pre-process emails during build time (e.g., via Artisan commands) to avoid runtime vulnerabilities.
- Will this package break if I update Laravel or Twig?
- The package’s maintenance status is unclear due to lack of recent updates, so breaking changes are a risk. Monitor the GitHub repository for updates and consider forking or replacing it if Laravel/Twig updates introduce incompatibilities. Test thoroughly after major version upgrades.
- How can I optimize performance for high-volume email campaigns?
- Avoid runtime inlining for large campaigns—use Laravel’s task scheduling or CI/CD pipelines to pre-process emails during build time. Cache inlined HTML in Redis or Memcached, or queue email processing with Laravel Queues to distribute the load. For critical paths, pre-generate inlined templates.
- Are there alternatives to twig/cssinliner-extra for Laravel Blade?
- Yes, for Blade templates, consider Premailer (PHP-based) or MJML (markup language for responsive emails). Both support CSS inlining and are more aligned with Laravel’s ecosystem. If you’re using Twig, this package is a lightweight option, but evaluate its maintenance risks before committing.
- Can I use this package with Laravel’s email system (e.g., Mailable classes)?
- Yes, integrate the package by applying the `inline_css` filter in your Twig email templates or within the `build()` method of a Mailable class. For example, render the Twig template first, then pass the output through the filter before sending. Combine with Laravel’s email queueing for scalability.