htmlburger/wpemerge-twig 问题修复 & 功能扩展

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

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

htmlburger/wpemerge-twig

Composer 安装命令:

composer require htmlburger/wpemerge-twig

包简介

Enables the use of Twig views in WP Emerge.

README 文档

README

Enables the use of Twig views in WP Emerge.

Quickstart

  1. Run composer require htmlburger/wpemerge-twig in your theme directory
  2. Add \WPEmergeTwig\View\ServiceProvider to your array of providers when booting WPEmerge:
    \App::make()->bootstrap( [
        'providers' => [
            \WPEmergeTwig\View\ServiceProvider::class,
        ],
    ] );

Options

Default options:

[
    // Automatically replace the default view engine for WP Emerge.
    'replace_default_engine' => true,

    // Pass .php views to the default view engine.
    // replace_default_engine must be true for this to take effect.
    'proxy_php_views' => true,

    // One or more directories to search for views.
    // Defaults to the main ['views'] key of the configuration.
    'views' => [get_stylesheet_directory(), get_template_directory()],

    // Options passed directly to Twig.
    'options' => [
        // 'cache' defaults to the main ['cache']['path'] key of the configuration.
        'cache' => 'wp-content/uploads/wpemerge/cache/twig',
    ],
]

You can change these options by specifying a twig key in your WP Emerge config array:

\App::make()->bootstrap( [
    // ... other WP Emerge options
    'twig' => [
        // ... other WP Emerge Twig options
        'options' => [
            // ... other Twig options
            'cache' => false,
        ],
    ],
] );

More information on what Twig options are supported is available on https://twig.symfony.com/doc/2.x/api.html.

Extending Twig

You can use the following to extend twig with a custom filter, for example:

$myfilter = new Twig_Filter( 'myfilter', function( $string ) {
    return strtoupper( $string );
} );

// \App::resolve() used for brevity's sake - use a Service Provider instead.
$twig = \App::resolve( WPEMERGETWIG_VIEW_TWIG_VIEW_ENGINE_KEY );
$twig->environment()->addFilter( $myfilter );

With this, you now have your very own custom Twig filter:

{{ 'hello world!' | myfilter }}

More information on how you can extend Twig is available on https://twig.symfony.com/doc/2.x/advanced.html#creating-extensions.

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 4
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-2.0-only
  • 更新时间: 2017-12-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固