Pass Variable And Output In Custom Email Template

The question:

I am trying to pass data into my email template, something like this:
[‘catalogue_url’ => ‘http://url.html‘]

I am struggling to access and output it in the email, I have tried the following:

Test 1: {{var $catalogue_url|raw}}

Test 2: {{var $catalogue_url}}

Test 3: {{var $catalogue_url}}

Test 4: {{var catalogue_url}}

Test 5: {{catalogue_url}}

My email sending code:

    $transport = $this->_transportBuilder
            'area' =>  $area,
            'store' => $this->storeManager->getStore()->getId(),
        ->setTemplateVars(['data' => $data])


I will try with $data.catalogue_url now.

What is wrong with this?

The Solutions:

Below are the methods you can try. The first solution is probably the best. Try others if the first one doesn’t work. Senior developers aren’t just copying/pasting – they read the methods carefully & apply them wisely to each case.

Method 1

Try this:

$templateOptions = [
             'area' => MagentoFrameworkAppArea::AREA_FRONTEND,
             'store' => $this->storeManager->getStore()->getId()
            $templateVars = [
                        'store' => $this->storeManager->getStore(),
                        'admin_name' => 'Admin',
                        'subject'    => 'subject',
                        'catalogue_url'    => 'pass url here'
            $from = ['email' => '[email protected]', 'name' => 'from name'];
            $to= "[email protected]"
            $transport = $this->transportBuilder->setTemplateIdentifier('template name or id')

Use in email template {{var catalogue_url}} variable

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Comment