candoimage/frctl_twig

Twig 扩展,可以无缝集成到 fractal twig 适配器

v1.0.0-alpha6 2019-04-24 05:35 UTC

This package is auto-updated.

Last update: 2024-09-24 18:03:26 UTC


README

FrctlTwigExtension 组件允许您无缝集成您的 Fractal twig 模板

安装

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

$ composer require candoimage/frctl_twig

用法

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

services:
    Frctl\Twig\Extension\FrctlTwigExtension:
        tags:
            - { name: twig.extension }

或在您的代码中手动注册

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

然后您需要 配置新的包含命名空间 以包含 fractal 模板

twig:
  paths:
    '%kernel.project_dir%/../frontend/src/components': FrctlTwig

或在您的代码中手动注册

$loader->addPath(dirname(__DIR__) . '/../frontend/src/components', 'FrctlTwig');

注册后,您可以在 twig 模板中无缝使用新的 render 标签 使用

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>title</title>
  </head>
  <body>
    {% render "@component" with {some: 'values'} %}
  </body>
</html>

高级示例

{# @component will have access to the variables from the current context and the additional ones provided #}
{% render'@component' with {'foo': 'bar'} %}

{# only the foo variable will be accessible #}
{% render'@component' with {'foo': 'bar'} only %}

{# @component will have access to the variables from the current context and the additional ones provided and the ones provided in the fractal yml config #}
{% render'@component' with {'foo': 'bar'} merge frctl context %}

{# only the foo variable and the ones provided in the fractal yml config will be accessible #}
{% render'@component' with {'foo': 'bar'} only merge frctl context %}

变量 variant 包含所选变体。

许可证

此组件受 MIT 许可证的保护。完整的许可证内容请参阅 LICENSE 文件。

报告问题或功能请求

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

作者信息

Peter Philipp @ Cando Image.

如果您认为这个组件很有用,请在 GitHub 仓库页面 上添加一个 ★。