PHPackages                             popov/zfc-block - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. popov/zfc-block

ActiveLibrary[Templating &amp; Views](/categories/templating)

popov/zfc-block
===============

Create separatly custom template bock with html, css, js etc.

0.0.1(8y ago)3167MITPHPPHP ^5.6 || ^7.0

Since Jul 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/popovserhii/zfc-block)[ Packagist](https://packagist.org/packages/popov/zfc-block)[ Docs](http://agere.com.ua)[ RSS](/packages/popov-zfc-block/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)DependenciesVersions (4)Used By (0)

ZF Block Helper
===============

[](#zf-block-helper)

Create separately custom template bock with html, css, js etc.

Usage
-----

[](#usage)

**For Expressive**: register `ZfcBlock` module in `config/config.php` with `Popov\ZfcBlock\ConfigProvider::class`.

**For MVC**: register with `Popov\ZfcBlock` in your configuration.

Create new `Block` class in your module with name `LoginBlock`

```
// src/Your/Module/src/Block/LoginBlock.php

namespace Stagem\Visitor\Block;

use Popov\ZfcBlock\Block\Core;
use Popov\ZfcUser\Form\LoginForm;

class LoginBlock extends Core
{
    /**
     * @var LoginForm
     */
    protected $loginForm;

    public function __construct(LoginForm $loginForm)
    {
        $this->loginForm = $loginForm;
    }

    public function getLoginForm()
    {
        return $this->loginForm;
    }
}
```

This class must extend `Popov\ZfcBlock\Block\Core` for allow usage basic functionality such as translate, check permission and other auxiliary opportunities.

Next step you can:

- create `Factory` for this block;
- use `ReflectionFactory`, this will be convenient if project is under development. Register factory in your `config/autoload/dependencies.global.php````
    return [
        // ...
        'block_plugins' => [
            'abstract_factories' => [
                Zend\ServiceManager\AbstractFactory\ReflectionBasedAbstractFactory::class
            ],
        ]
    ];
    ```

If you decide use `ReflectionFactory` then minimum bare you need add alias for your block to configuration

```
// src/Stagem/Visitor/config/module.config.php
return [
    // ...
    'block_plugins' => [
        'aliases' => [
            'VisitorLogin' => \Your\Module\Block\LoginBlock::class,
        ],
    ],
    'block_plugin_config' => [
        'default' => [
            \Your\Module\Block\LoginBlock::class => [
                'template' => 'visitor::login'
            ],
        ],
    ],
];
```

> Be aware. Don't use `ReflactionFactory` on production, create real `Factory` for your block class.

After that your can call your block in any template with

```
