-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Use the Twig guard tag #6656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the Twig guard tag #6656
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,13 @@ | ||||||||
| {# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #} | ||||||||
| {% for css_asset in assets %} | ||||||||
| {% set href = asset(css_asset.value, css_asset.packageName) %} | ||||||||
| <link rel="stylesheet" href="{{ (css_asset.preload ? ea_call_function_if_exists('preload', href, { as: 'style', nopush: css_asset.nopush }))|default(href) }}" | ||||||||
| {%- for attr, value in css_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}> | ||||||||
| {% if css_asset.preload %} | ||||||||
| {% guard function preload %} | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In most Symfony projects, yes. In this project, we always check (and throw an exception) if you don't have the needed code for some feature that you are using (see e.g. EasyAdminBundle/src/Config/Asset.php Lines 69 to 71 in da8f4e2
Then, if we always check first, why do we need this |
||||||||
| {% set href = asset(css_asset.value, css_asset.packageName) %} | ||||||||
| <link rel="stylesheet" href="{{ preload(href, { as: 'style', nopush: css_asset.nopush }) }}" | ||||||||
| {%- for attr, value in css_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}> | ||||||||
| {% endguard %} | ||||||||
| {% else %} | ||||||||
| <link rel="stylesheet" href="{{ asset(css_asset.value, css_asset.packageName) }}" | ||||||||
| {%- for attr, value in css_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}> | ||||||||
| {% endif %} | ||||||||
| {% endfor %} | ||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| {# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #} | ||
| {% for encore_asset in assets %} | ||
| {{ ea_call_function_if_exists('encore_entry_link_tags', encore_asset.value, encore_asset.webpackPackageName, encore_asset.webpackEntrypointName, encore_asset.htmlAttributes) }} | ||
| {% guard function encore_entry_link_tags %} | ||
| {{ encore_entry_link_tags(encore_asset.value, encore_asset.webpackPackageName, encore_asset.webpackEntrypointName, encore_asset.htmlAttributes) }} | ||
| {% endguard %} | ||
| {% endfor %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| {# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #} | ||
| {% for encore_asset in assets %} | ||
| {{ ea_call_function_if_exists('encore_entry_script_tags', encore_asset.value, encore_asset.webpackPackageName, encore_asset.webpackEntrypointName, encore_asset.htmlAttributes) }} | ||
| {% guard function encore_entry_script_tags %} | ||
| {{ encore_entry_script_tags(encore_asset.value, encore_asset.webpackPackageName, encore_asset.webpackEntrypointName, encore_asset.htmlAttributes) }} | ||
| {% endguard %} | ||
| {% endfor %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| {# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #} | ||
| {{ ea_importmap(assets|map(asset => asset.value)) }} | ||
| {% guard function importmap %} | ||
| {{ importmap(assets|map(asset => asset.value)) }} | ||
| {% endguard %} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,13 @@ | ||
| {# @var assets \EasyCorp\Bundle\EasyAdminBundle\Dto\AssetDto[] #} | ||
| {% for js_asset in assets %} | ||
| {% set src = asset(js_asset.value, js_asset.packageName) %} | ||
| <script src="{{ (js_asset.preload ? ea_call_function_if_exists('preload', src, { as: 'script', nopush: js_asset.nopush }))|default(src) }}" {{ js_asset.async ? 'async' }} {{ js_asset.defer ? 'defer' }} | ||
| {%- for attr, value in js_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}></script> | ||
| {% if js_asset.preload %} | ||
| {% guard function preload %} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
| {% set src = asset(js_asset.value, js_asset.packageName) %} | ||
| <script src="{{ preload(src, { as: 'script', nopush: js_asset.nopush }) }}" {{ js_asset.async ? 'async' }} {{ js_asset.defer ? 'defer' }} | ||
| {%- for attr, value in js_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}></script> | ||
| {% endguard %} | ||
| {% else %} | ||
| <script src="{{ asset(js_asset.value, js_asset.packageName) }}" {{ js_asset.async ? 'async' }} {{ js_asset.defer ? 'defer' }} | ||
| {%- for attr, value in js_asset.htmlAttributes %} {{ attr }}="{{ value|e('html') }}"{% endfor %}></script> | ||
| {% endif %} | ||
| {% endfor %} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified as
^5.4.48|^6.4.16|^7.1.9There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make this change, thanks 🙏