redant/twig-components-bundle
Composer 安装命令:
composer require redant/twig-components-bundle
包简介
Twig Components bundle for Symfony
README 文档
README
A Symfony bundle for the Twig Components library.
This bundle allows you to create robust, reusable and automatically documented
Twig components using the new component tag. Twig components allow you to quickly
build and maintain your own UI toolkit, where each button, table or card has to be
designed only once and can be used throughout your entire application.
This Twig Components bundle for Symfony makes life a little bit easier by automatically searching your template directories for defined components, every time the Symfony container is compiled.
For more information about Twig Components, see the documentation.
Setup and Usage
You can install this bundle through Composer:
$ composer require redant/twig-components-bundle
When this bundle is enabled in your Symfony bundle configuration, if will search all your template directories for defined components, every time the container is compiled.
This includes:
- The
templates/componentsfolder (main application templates) - Every installed bundle's
Resources/views/componentsfolder (if defined)
Global variable
If you don't like the name of the global variable that defines the components,
use the twig_components.global_variable parameter to change this:
# app/config/twig.yaml twig_components: global_variable: 'ui'
This will register the button component as ui.button().
Note: If you set the prefix to false, no Twig global will be registered for
defined components. You can then only use the render_component function.
Namespaces
If you define your components in subdirectories of the components/ directory, the
additional directories will namespace your component.
For example, a component defined in components/ui/button.html.twig
will be accessible as component.ui.button({}) or via
render_component('ui.button', {}).
Generate documentation
The added bonus to creating component definitions is the automatic creation of documentation. It explains, for instance, what your component can be used for and which parameters it accepts. For example, the Twig Components bundle can automatically generate a table like this for an example button component:
| Property | Type | Default value | Comment |
|---|---|---|---|
| container | string |
button |
HTML container element |
| classes | string[] |
[ 'small' ] |
Additional button classes |
| label* | string |
Button text (rendered as raw HTML) | |
| url | string |
Hyperlink | |
| confirm | bool |
false |
You can generate a static HTML file with documentation using the supplied
twig:components:generate-docs command.
Description: Generate documentation for Twig components Usage: twig:components:generate-docs [options] <path> Arguments: path Output directory Options: --title=TITLE Title for the generated documentation [default: "Twig components"] --generic Disregard twig_component.global_variable settings and only show render_component() examples```
Pro tip: When you start your component template file with a comment ({# ... #}),
its contents will be added at the top of the documentation for the component.
License
This library is licensed under the MIT License - see the LICENSE file for details.
redant/twig-components-bundle 适用场景与选型建议
redant/twig-components-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.92k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2019 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 redant/twig-components-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 redant/twig-components-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 18.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-01