I want to check that the user is newsletter subscriber or not in email footer template in admin panel. I am unable to find a variable which can check like this:

{{ if($userIsSubscriber) { //Code//}}}

I know above syntax is wrong but I need code somewhat like this as I want to show some specific part of template to our user who are subscribers.


  • Where you want to check this condition in template or block? Apr 9, 2019 at 7:21
  • I wan to check it in my footer template of email (In Marketing->Email Templates->footer template of my current theme)
    – Stack user
    Apr 9, 2019 at 7:30
  • In Magento 2 Backend
    – Stack user
    Apr 9, 2019 at 7:30
  • like {{var subscriber.getUnsubscriptionLink()}} I want to use {{var subscriber.isSubscribed()}}
    – Stack user
    Apr 9, 2019 at 8:34

1 Answer 1


You can use \Magento\Newsletter\Model\SubscriberFactory
class in your constructor by injecting it like this:

protected $subscriberFactory;

public function __construct(
    \Magento\Newsletter\Model\SubscriberFactory $subscriberFactory
    $this->subscriberFactory= $subscriberFactory;

Then in your execute function you can check customer if subscribe or not to the newsletter.

public function execute()
   $customerId = 1;
   $userIsSubscriber = $this->subscriberFactory->loadByCustomerId($customerId);

   if ($userIsSubscriber->isSubscribed()) {
       // return Customer is subscribed
   } else {
       // return Customer is not subscribed

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.