title: Magento 2 Helpers and best way to use helper method in phtml
body: <p>There seems to be a couple of ways that you can load a helper to be used inside of a phtml file. However, I don't quite understand the advantages and disadvantages of the ways.</p>
  
  <ol>
  <li>It seems the preferred Magento 2 way is to create a custom block and in the construct load the helper...</li>
  </ol>
  
  <pre><code>namespace Company\Module\Block;
  
  use \Magento\Framework\View\Element\Template\Context;
  use \Company\Module\Helper\Data;
  
  
  class Module extends \Magento\Framework\View\Element\Template
  {
  
      private $_helper;
  
      public function __construct(Context $context, Data $helper)
      {
          $this-&gt;_helper = $helper;
          parent::__construct($context);
      }
  
      public function isLoggedIn()
      {
  
          return $this-&gt;_helper-&gt;isUserLoggedIn();
      }
  
  }
  </code></pre>
  
  <p>And then use in phtml like this:</p>
  
  <pre><code>$block-&gt;isLoggedIn()
  </code></pre>
  
  <ol start="2">
  <li>Another way, which seems to be discouraged(but works), is to load a helper via the phtml:</li>
  </ol>
  
  <pre><code>$helper = $this-&gt;helper('Company\Module\Helper\Data');
  $helper-&gt;isLoggedIn();
  </code></pre>
  
  <ul>
  <li>Why is this discouraged? </li>
  </ul>
  
  <p>And finally...</p>
  
  <ol start="3">
  <li>Would it be considered bad practice if I make my helper <code>public</code> in the block that way I don't need to proxy the methods?</li>
  </ol>
  
  <pre><code>namespace Company\Module\Block;
  
  use \Magento\Framework\View\Element\Template\Context;
  use \Company\Module\Helper\Data;
  
  
  class Module extends \Magento\Framework\View\Element\Template
  {
  
      public $helper;
  
      public function __construct(Context $context, Data $helper)
      {
          $this-&gt;helper = $helper;
          parent::__construct($context);
      }
  </code></pre>
  
  <p>And then use in the phtml as needed:</p>
  
  <pre><code>$block-&gt;helper-&gt;isLoggedIn()
  </code></pre>
  
  <p>Love to hear thoughts between these 3 ways to use a helper in phtml. I prefer to use Approach #2 because then I don't need to create custom blocks just to use a helper in a phtml file. However, if this is going to cause major slow down or issues I will avoid it. </p>