Skip to main content

M2 | Magento 2 - How to print array values in custom html email template by looping?

I want to print multiple coupon/gift codes in the custom email template. I am getting a single code as:

$templateVars = array(   'store' => $this->storeManager->getStore(),   'customer_name' =>$name=> $name,   'giftcods' => 'VFDFRVXSW43VF'  ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;">    <strong>{{var giftcods|raw}}</strong>  </div> 

And output as:

[![enter image description here][1]][1]enter image description here

But this is a single code, I wantwon't to print multiple codes in an email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in the HTML template.

Edit:

In vendor/magento/module-gift-cardvendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [   'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'),   'sender_name' => $senderName,   'giftcards' => $codeList->toHtml(),   'balance' => $balance,   'is_multiple_codes' => 1 < $generatedCodesCount,   'store' => $giftCardOrderItem->getStore(), .................. ..................  ]; 

Here

$codeList

$codeList is not array. But still looking to solve  ! [1]: https://i.sstatic.net/Q4Wvo.png

M2 | How to print array values in custom html email template by looping?

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array(   'store' => $this->storeManager->getStore(),   'customer_name' =>$name,   'giftcods' => 'VFDFRVXSW43VF'  ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;">    <strong>{{var giftcods|raw}}</strong>  </div> 

And output as:

[![enter image description here][1]][1]

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [   'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'),   'sender_name' => $senderName,   'giftcards' => $codeList->toHtml(),   'balance' => $balance,   'is_multiple_codes' => 1 < $generatedCodesCount,   'store' => $giftCardOrderItem->getStore(), .................. ..................  ]; 

Here

$codeList

is not array. But still looking to solve  ! [1]: https://i.sstatic.net/Q4Wvo.png

Magento 2 - How to print array values in custom html email template by looping?

I want to print multiple coupon/gift codes in the custom email template. I am getting a single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' => $name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

enter image description here

But this is a single code, I won't to print multiple codes in an email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in the HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [ 'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'), 'sender_name' => $senderName, 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $generatedCodesCount, 'store' => $giftCardOrderItem->getStore(), .................. .................. ]; 

Here $codeList is not array. But still looking to solve!

added 10 characters in body
Source Link
Ajwad Syed
  • 1.6k
  • 30
  • 63

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' =>$name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

[![enter image description here][1]][1]

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [ 'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'), 'sender_name' => $senderName, 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $generatedCodesCount, 'store' => $giftCardOrderItem->getStore(), .................. .................. ]; 

Here $codeList

$codeList

is not array. But still looking to solve ! [1]: https://i.sstatic.net/Q4Wvo.png

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' =>$name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

[![enter image description here][1]][1]

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [ 'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'), 'sender_name' => $senderName, 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $generatedCodesCount, 'store' => $giftCardOrderItem->getStore(), .................. .................. ]; 

Here $codeList is not array. But still looking to solve ! [1]: https://i.sstatic.net/Q4Wvo.png

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' =>$name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

[![enter image description here][1]][1]

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [ 'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'), 'sender_name' => $senderName, 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $generatedCodesCount, 'store' => $giftCardOrderItem->getStore(), .................. .................. ]; 

Here

$codeList

is not array. But still looking to solve ! [1]: https://i.sstatic.net/Q4Wvo.png

added 951 characters in body
Source Link
Ajwad Syed
  • 1.6k
  • 30
  • 63

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' =>$name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

enter image description here [![enter image description here][1]][1]

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [ 'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'), 'sender_name' => $senderName, 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $generatedCodesCount, 'store' => $giftCardOrderItem->getStore(), .................. .................. ]; 

Here $codeList is not array. But still looking to solve ! [1]: https://i.sstatic.net/Q4Wvo.png

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' =>$name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

enter image description here

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

I want to print multiple coupon/gift codes in custom email template. I am getting single code as:

$templateVars = array( 'store' => $this->storeManager->getStore(), 'customer_name' =>$name, 'giftcods' => 'VFDFRVXSW43VF' ); 

In HTML Template file:

<div style="color:#696969;font-size:20px;text-align:center;"> <strong>{{var giftcods|raw}}</strong> </div> 

And output as:

[![enter image description here][1]][1]

But this is single code, I want print multiple codes in email. I have gone by some related links like:

Magento 2 : How to handle array values in custom email templates?

Pass Variable And Output In Custom Email Template

But there is no proper solution available specially about how to deal with array value in HTML template.

Edit:

In vendor/magento/module-gift-card Module this is done as

In file: vendor/magento/module-gift-card/view/frontend/email/gift_information.html

{{if is_multiple_codes}} <h3>{{trans "Gift Card Codes:"}}</h3> {{else}} <h3>{{trans "Gift Card Code:"}}</h3> {{/if}} <p>{{var giftcards|raw}}</p> 

Variables are sending by Magento\GiftCard\Model\GiftCardItemEmail.php as:

$templateData = [ 'name' => $giftCardOrderItem->getProductOptionByCode('giftcard_recipient_name'), 'sender_name' => $senderName, 'giftcards' => $codeList->toHtml(), 'balance' => $balance, 'is_multiple_codes' => 1 < $generatedCodesCount, 'store' => $giftCardOrderItem->getStore(), .................. .................. ]; 

Here $codeList is not array. But still looking to solve ! [1]: https://i.sstatic.net/Q4Wvo.png

edited title
Link
Ajwad Syed
  • 1.6k
  • 30
  • 63
Loading
Source Link
Ajwad Syed
  • 1.6k
  • 30
  • 63
Loading