定制 gubler/twig-extensions 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

gubler/twig-extensions

Composer 安装命令:

composer require gubler/twig-extensions

包简介

Twig extensions for internal projects

关键字:

README 文档

README

This project provides several Twig extensions for internal projects.

Installation

The preferred method of installation is via Composer. Run the following command to install the package and add it as a requirement to your project's composer.json:

composer require gubler/twig-extensions

Configuration

$twig = new Twig_Environment($loader, $options);
$twig->addExtension(new Gubler\Twig\Extension\FileIconClassExtension());
$twig->addExtension(new Gubler\Twig\Extension\FlashMessagesExtension());
$twig->addExtension(new Gubler\Twig\Extension\InstanceOfExtension());
$twig->addExtension(new Gubler\Twig\Extension\TableSortIconExtension());

For Symfony, register it in your services.yaml

services:
    gubler.twig_extension.file_icon_class:
        class: Gubler\Twig\Extension\FileIconClassExtension
        tags: [twig.extension]
    gubler.twig_extension.flash_messages:
        class: Gubler\Twig\Extension\FlashMessagesExtension
        tags: [twig.extension]
    gubler.twig_extension.instance_of:
        class: Gubler\Twig\Extension\InstanceOfExtension
        tags: [twig.extension]
    gubler.twig_extension.table_sort_icon:
        class: Gubler\Twig\Extension\TableSortIconExtension
        tags: [twig.extension]

You can also use the MimeTypeToIconClass library directly and inject it into your classes by registering it as a service:

services:
    Gubler\Twig\Extension\Lib\MimeTypeToIconClass: ~

Extensions

FileIconClass

This maps a mimetype to a FontAwesome file icon. This currently only supports the following filetypes:

  • MS Word
  • MS Excel
  • MS PowerPoint
  • PDF

All other files return a generic file icon.

{{ 'application/vnd.ms-excel'|fileIconClass }}

FlashMessages

This extension will iterate through the flashes of a given Session and convert them to Bootstrap 5 alerts.

This looks for the flash keys of success, warning, error, and notice.

Creating the flashes:

# In a Symfony controller:
$this->addFlash('success', 'This is a SUCCESS message');
$this->addFlash('error', 'This is an ERROR message');
$this->addFlash('warning', 'This is a WARNING message');
$this->addFlash('notice', 'This is a NOTICE message');

Rendering all flashes:

{{ flashMessages(app.session) }}

InstanceOf

This extension provides PHP's instanceof type operator as a Twig test.

{# date is \DateTime object #}
{{ date is instanceof("\\DateTime") ? 'ok' : 'bad' }}

TableSortIcon

This filter allows you to pass the column name, the sorted column name, and sort direction and get back a FontAwesome sorting icon classes.

<i class="{{ tableSortIcon('col1', 'col1', 'asc') }}"></i>

Contributing

Contributions are welcome! Please read CONTRIBUTING for details.

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you are expected to uphold this code.

Copyright and License

The gubler/twig-extensions library is copyright © Daryl Gubler and licensed for use under the MIT License (MIT). Please see LICENSE for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固