FYS Hook Bundle
Description
FYS Hook Bundle allows you to make a hook and simply call it in twig templating engine, (*1)
Installation
composer require fys/hook-bundle
Creating first hook
first, create a service that tagged to hook.type, (*2)
// services.yml
app.hook.head:
class: AppBundle\Component\Hooks\HeadHook
tags:
- { name: hook.type }
second, create the class that you mentioned in the service, (*3)
// AppBundle/Component/Hooks/HeadHook.php
namespace AppBundle/Component/Hooks;
use FYS\HookBundle\Component\HookInterface;
class HeadHook implements HookInterface
{
public function getName()
{
// the hook name, for example "head"
return 'head';
}
pubilc function getAction()
{
// the action when the hook is called
return 'HELLO THIS IS MY FIRST HOOK';
}
public function getPriority()
{
// the priority of this hook
return 1;
}
}
note: the hook class should implements HookInterface
then, you can call {{ call_hook('head') }} in twig template, it will print "HELLO THIS IS MY FIRST HOOK", (*4)