fys / hook-bundle
provide hook on twig template
1.0.1
2016-04-29 07:53 UTC
Requires
- php: >=5.3.0
This package is auto-updated.
Last update: 2025-01-15 06:31:22 UTC
README
Description
FYS Hook Bundle allows you to make a hook and simply call it in twig templating engine
Installation
composer require fys/hook-bundle
Creating first hook
first, create a service that tagged to hook.type
// services.yml
app.hook.head:
class: AppBundle\Component\Hooks\HeadHook
tags:
- { name: hook.type }
second, create the class that you mentioned in the service
// 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"