🔥  Hot Reload for JS and CSS now available! With Zermatt v1.2.0. Read more.

Docs
Container

Container

Easy access to view models.

The Container is a way to use view models in templates without the need to declare them in XML layout files.

All classes that are called by the Container must implement \Magento\Framework\View\Element\Block\ArgumentInterface.

Usage

Create a view model class that implements \Magento\Framework\View\Element\Block\ArgumentInterface.

class Vendor\Module\Hello implements \Magento\Framework\View\Element\Block\ArgumentInterface
{
    public function world(): string {
        return __('Hello World!');
    }
}

Use it in templates:

<?php
use Maddlen\Zermatt\App\Container;
use Vendor\Module\Hello;
/** @var Vendor\Module\Hello $hello */
$hello = Container::get(Hello::class)
?>
<p><?= $hello->world() ?></p>