-2

is passing a variable to a twig macro inside the assets function even possible, for example it doesn't work with with concatenaciton:

Macro:

{% macro card(image) %}
    <div class="card">
        <img src="{{ asset('assets/images/' ~ {{image}} ~ '.svg') }}" alt="" />
    </div>
{% endmacro %}

Calling the macro:

{{ macros.card('questions.svg'}}
DarkBee
  • 16,592
  • 6
  • 46
  • 58
Lukas Hillebrand
  • 390
  • 5
  • 20
  • Duplicate of the following [question](https://stackoverflow.com/questions/7704253/how-to-concatenate-strings-in-twig) – DarkBee Jul 06 '22 at 12:32

1 Answers1

0

this works

<img src="{{ asset('assets/images/' ~ image ) }}" alt="" />

The double curly braces {{ exampleVariableName }} that are used in twig for variables are not necessary inside the asset function. I think it causes problems with internal interpolation

Rohit Gupta
  • 4,022
  • 20
  • 31
  • 41
Lukas Hillebrand
  • 390
  • 5
  • 20
  • 1
    Please explain your answer – Rohit Gupta Jul 07 '22 at 00:59
  • The double curly braces {{ exampleVariableName }} that are used in twig for variables are not necessary inside the asset function. I think it causes problems with internal interpolation. – Lukas Hillebrand Jul 07 '22 at 09:56
  • 1
    The explanation was not for me. I have added it to your answer. Your answer is considered low quality by StackOverflow unless it is complete with example, explanation and reference. I have upvoted it now. – Rohit Gupta Jul 07 '22 at 11:23
  • 1
    That explanation is just incorrect though and has nothing to do with interpolation. As pointed out in the question I've linked this is mere a concatenation of two (or more) string. Furthermore, the `{{ ... }}` is used to output content. So this is just a syntactically error, nothing more – DarkBee Jul 07 '22 at 13:51