Inline mail CSS via AssetMapper instead of static file path - #242
Open
jonasdekeukelaere wants to merge 3 commits into
Open
Inline mail CSS via AssetMapper instead of static file path#242jonasdekeukelaere wants to merge 3 commits into
jonasdekeukelaere wants to merge 3 commits into
Conversation
Add MailCssExtension exposing a mail_css() Twig function that reads the compiled mail.scss asset through AssetMapper, and use it in Mail/base.html.twig instead of referencing the compiled CSS file directly. Requires symfony/asset-mapper.
Contributor
Reviewer's GuideThis PR replaces the mail template’s direct reference to a compiled CSS file with a Twig function that fetches the compiled mail styles via Symfony’s AssetMapper, wiring a new Twig extension into the service container and adding the AssetMapper dependency. Sequence diagram for mail_css Twig function inlining CSSsequenceDiagram
participant TwigTemplate as Mail_base_html_twig
participant MailCssExtension
participant AssetMapperInterface
participant inline_css as inline_css_filter
TwigTemplate->>MailCssExtension: mail_css()
MailCssExtension->>AssetMapperInterface: getAsset(styles/mail.scss)
AssetMapperInterface-->>MailCssExtension: Asset(content)
MailCssExtension-->>TwigTemplate: getMailCss() content
TwigTemplate->>inline_css: inline_css(mail_css() content)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Consider handling the case where
AssetMapperInterface::getAsset('styles/mail.scss')returnsnullto avoid potential runtime errors when the asset is missing or misconfigured. - If
mail_css()is called multiple times in a single request, you may want to cache the asset content in the extension to avoid repeated reads from the asset mapper.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider handling the case where `AssetMapperInterface::getAsset('styles/mail.scss')` returns `null` to avoid potential runtime errors when the asset is missing or misconfigured.
- If `mail_css()` is called multiple times in a single request, you may want to cache the asset content in the extension to avoid repeated reads from the asset mapper.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Member
|
Wouldn't it be better to have a more generic Twig function? Which allows to pass a path. Eg: |
Rename MailCssExtension to AssetContentExtension and mail_css() to asset_content(string $path), allowing any AssetMapper asset path to be read rather than only the mail stylesheet.
Member
Author
|
@tijsverkoyen Good call — done in d5ac878: renamed |
tijsverkoyen
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MailCssExtensionexposing amail_css()Twig function that reads the compiledstyles/mail.scssasset through AssetMappermail_css()inMail/base.html.twiginstead of referencing the compiled CSS file directly viacontent('/../var/sass/mail.output.css')symfony/asset-mapper: ^8.0🤖 Generated with Claude Code
Summary by Sourcery
Inline mail template CSS via AssetMapper-backed Twig function instead of a hardcoded compiled CSS file path.
New Features:
Enhancements:
Build: