tmilos/symfony-control

1.0.1 2016-02-04 11:02 UTC

This package is not auto-updated.

Last update: 2024-10-26 19:10:47 UTC


README

License Build Status Coverage Status

Symfony bundle implementing the Twig control tag. Easy rendering of blocks with ability to pass specified parameters trough new control twig tag.

Installation

Require tmilos/symfony-control with composer

require tmilos/symfony-control

Add the bundle to your AppKernel

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

Control twig tag

{% control BLOCK_NAME with EXPRESSION %}

It will display specified BLOCK_NAME with specified EXPRESSION put as the value of the control variable available only in that block scope.

property twig function

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

Returns value of the object's property

Wrapper around Symfony\Component\PropertyAccess\PropertyAccessor::getValue()

has_property twig function

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

Returns bool

Wrapper around Symfony\Component\PropertyAccess\PropertyAccessor::isReadable()

Usage Example

{# 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 %}