Magento 2: proper use of helpers
Don't.
This is like using ObjectManager::getInstance()->create()
in a template!
Use a custom Block that receives the helper as a constructor dependency instead, and add a proxy method that calls the helper method.
In the template:
$block->customMethod()
In the block:
public function __construct(Path/To/Helper/Class $helperClass, ...other dependencies...)
{
$this->helper = $helperClass;
// ...other assignments and call to parent::__construct()
}
public function customMethod()
{
return $this->helper->customMethod();
}
In OOP principle speak this avoids violating the "Law of Demeter". It encapsulates the business logic in the block instead of the template. As a side effect it also makes the logic more testable as the logic is moved into the block.
Regarding what logic put into the helper classes, I find that in Magento 2 helpers mostly make sense for services, like something that is not a model, but contains reusable code, for example price formatting (which is contained in the core, but I can't think of a better example right now).