maceda/twig-composer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

maceda/twig-composer

Composer 安装命令:

composer require maceda/twig-composer

包简介

Callback library for Twig

README 文档

README

A callback function library for Twig: you will be able to execute code when templates are rendered.

Useful for calling code like controllers, etc. before the template is rendered. This can be done in some frameworks as Symfony or Laravel, but this library works directly with Twig.

For example, if you have a menu.twig template which can be included in a layout, you can do:

    TwigComposer::getNotifier()->on('menu.twig', [$menuService,generateDinamicMenu]);

And then use the menu generated in menu.twig template. You won't need to include a call to the service in each controller which uses the layout.

Getting Started

If you are using composer tool, you can start using TwigComposer requiring the library:

require maceda/twig-composer

If not, please follow installation instructions.

To be notified of template renders, you need to indicate TwigComposer as the base class for templates when creating Twig_Environment:

$this->twig = new \Twig_Environment(
$loader,
array(
     ...
     'base_template_class' => 'TwigComposer\TwigComposer',
     ...
));

To receive callbacks you must register them for each template you want to be notified:

TwigComposer::getNotifier()->on('Template_I_Want_To_Watch', $callback);

$callback will be called each time 'Template_I_Want_To_Watch' is rendered.

You can also inherit your own base class from TwigComposer if you need to use your own base class for Twig (do not forget to call parent methods when corresponding)

Installation

If you do not use composer, you must install and require the following dependencies:

You must also include Relayer.php and TwigComposer.php in your project to use this library.

Running the tests

This library uses PHPUnit for test. To run the test, execute this command:

/usr/bin/php ./vendor/phpunit/phpunit/phpunit ./tests

If you want to generate code coverage information, just add the option --coverage-html DIRECTORY

Contributing

Feel free to contribute to this code. Please send an email to the authors and / or a pull request to the project's repository: https://github.com/AlvaroMaceda/twig-composer

Authors

License

This project is Public Domain.

Acknowledgments

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Public
  • 更新时间: 2016-10-31

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固