0

I need to display image at my twig file. I am passing filename information as below:

    $emailContent = [
        'filename' => "$filename.png"
    ];

    $this->sendMail(
        ,,,
        ...
        'Emails/content.html.twig',
        $emailContent
    );

In my twig file, when I put the filename directly it works.

<img src="{{ email.image("@images/1000.png") }}" alt="It Works!!">

But, I am not sure how to pass filename from controller to twig html file.

I already tried following lines:

<img src="{{ email.image("@images/{{ filename }}") }}" alt="test ONLY">
<img src="{{ asset("images/logo/") ~ filename }} " alt="???" />

It didn't worked.

Can anybody please help.

3
  • 1
    <img src="{{ email.image("@images/" ~ filename) }}" alt="test ONLY">? Commented May 28, 2021 at 13:52
  • @biesior yes its my custom method which later sends email using TemplatedEmail of Symfony Commented May 28, 2021 at 13:55
  • Thanks u_mulder , it worked. I understand my mistake. Many Thanks Commented May 28, 2021 at 13:57

1 Answer 1

1

Use concatenation for argument of email.image:

<img src="{{ email.image("@images/" ~ filename) }}" alt="test ONLY">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.