vscode-twig-language
vscode-twig-language copied to clipboard
Default value support for macro arguments
Hello junstyle,
Thank you for this extension. When writing this piece of code:
{% macro menuLink(href, config, active = false, class = '') %}
the extension reports the following "problem":
ERROR: Expected comma or ")". The argument list of a macro can only consist of parameter names separated by commas.
but Twig supports default values for arguments nowadays.
Can this be fixed?
@hansgrinwis in the meantime, i believe you can write this using the default() filter inside your macro:
{% macro menuLink(href, config, active, class) %}
<a href="{{ href }}" class="{{ active|default(false) ? 'active' }} {{ class|default('') }}">{{ config.label }}</a>
{% endmacro %}
Obviously i’m assuming here that you have an object for config with a label key, but the rest of the code should match with your case and work.
@furioursus That's a nice workaround. Thank you!