tmilos/symfony-control

安装: 11

依赖: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:bundle

1.0.1 2016-02-04 11:02 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:42:10 UTC


README

License Build Status Coverage Status

Symfony bundle 实现了 Twig 控制标签。通过新的 control twig 标签,可以轻松渲染块,并传递指定的参数。

安装

使用 composer 需要 tmilos/symfony-control

require tmilos/symfony-control

将包添加到您的 AppKernel

class AppKernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Tmilos\ControlBundle\TmilosControlBundle(),
            // ...
        );
    }
}

控制 twig 标签

{% control BLOCK_NAME with EXPRESSION %}

它将显示指定的 BLOCK_NAME,并将指定的 EXPRESSION 作为 control 变量的值,仅在当前块作用域内有效。

property twig 函数

{{ property(object, 'path.to.property') }}

返回对象属性的值

围绕 Symfony\Component\PropertyAccess\PropertyAccessor::getValue() 的包装

has_property twig 函数

{{ has_property(object, 'path.to.property') }}

返回 bool

围绕 Symfony\Component\PropertyAccess\PropertyAccessor::isReadable() 的包装

使用示例

{# table.html.twig #}

{% block table %}
    <table>
        <tr>
        {% for col in control.columns %}
            <th>{{ col|trans }}</th>
        {% endfor
        </tr>
        {% for row in control.rows %}
        <tr>
            {% for col in control.columns %}
            <td>
                {{ has_property(row, col) ? property(row, col) : block(col) }}
            </td>
            {% endfor %}
        </tr>
        {% endfor
    </table>
{% endblock %}
{# index.html.twig #}

{% extends 'base.html.twig' %}

{% use 'table.html.twig' %}

{% block body %}
    {% control table with {
        columns: ['name', 'user.email', 'special_column'],
        rows: entities
    } %}
{% endblock %}

{% block special_column %}
    <a href="{{ path('foo', {id: row.id}) }}">edit</a>
{% endblock %}