djboris88/twig-commented-include

输出在`include`标签前后HTML注释的Twig扩展

2.0.0 2024-01-16 21:27 UTC

This package is auto-updated.

Last update: 2024-09-16 22:57:41 UTC


README

这是一个简单的Twig扩展,有助于调试和导航项目中的多个Twig部分。在渲染模板时,它会输出每个include语句前后的HTML注释。注释看起来像这样

<!-- Begin output of "_partials/_navigation.twig" -->
<div class="navigation" role="navigation" data-navigation>...</div>
<!-- / End output of "_partials/_navigation.twig" -->

安装

要安装此组件的最新稳定版本,请打开控制台并执行以下命令

composer require djboris88/twig-commented-include

用法

第一步是将扩展注册到twig环境中

/** @var $twig Twig_Environment */
$twig->addExtension(new Djboris88\Twig\Extension\CommentedIncludeExtension());

一旦注册,它将自动在Twig文件中的每个include标签前后添加HTML注释。

Symfony Bundle

如果您想在您的Symfony应用程序中使用此扩展,可以启用此包中包含的Symfony Bundle。

该Bundle将自动注册twig扩展。

Symfony 2/3

// app/AppKernel.php
if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
    $bundles[] = new Djboris88\Twig\Extension\CommentedIncludeTwigExtensionBundle();
}

Symfony 4

// config/bundles.php
//...
return [
    //...
    Djboris88\Twig\Extension\CommentedIncludeTwigExtensionBundle::class => ['dev' => true]
];

许可证

此组件受GPL 3.0许可证的保护。请参阅LICENSE文件中的完整许可证。

报告问题或功能请求

问题和功能请求在Github问题跟踪器中跟踪。

作者信息

由Boris Đemrovski倾情开发。

如果您觉得这个组件很有用,请在此GitHub仓库页面和/或Packagist包页面上添加★。