Webiny\Component\TemplateEngine\Bridge\Smarty\Smarty::registerPlugin PHP Method

registerPlugin() public method

Register a plugin for the template engine.
public registerPlugin ( Plugin $plugin ) : void
$plugin Webiny\Component\TemplateEngine\Plugin
return void
    public function registerPlugin(Plugin $plugin)
    {
        try {
            $this->smarty->registerPlugin($plugin->getType(), $plugin->getName(), $plugin->getCallbackFunction(), $plugin->getAttribute('Cachable', true), $plugin->getAttribute('CacheAttr', null));
        } catch (\SmartyException $e) {
            throw new SmartyException($e);
        }
    }

Usage Example

Example #1
0
 /**
  * @dataProvider dataProvider
  */
 public function testRegisterPlugin(Smarty $smarty)
 {
     $plugin = new PluginMock();
     $smarty->registerPlugin($plugin);
     $smarty->assign('name', 'world');
     $result = $smarty->fetch('TestPlugin.tpl');
     $this->assertSame('Hello WORLD', $result);
 }