symfony-control
, (*1)
Symfony bundle implementing the Twig control tag. Easy rendering of blocks with ability to pass specified parameters trough
new control
twig tag., (*2)
Installation
Require tmilos/symfony-control
with composer, (*3)
``` bash
require tmilos/symfony-control, (*4)
Add the bundle to your AppKernel
``` php
class AppKernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Tmilos\ControlBundle\TmilosControlBundle(),
// ...
);
}
}
Control twig tag
``` twig
{% control BLOCK_NAME with EXPRESSION %}, (*5)
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
``` twig
{{ property(object, 'path.to.property') }}
Returns value of the object's property, (*6)
Wrapper around Symfony\Component\PropertyAccess\PropertyAccessor::getValue()
, (*7)
has_property twig function
``` twig
{{ has_property(object, 'path.to.property') }}, (*8)
Returns bool
Wrapper around ``Symfony\Component\PropertyAccess\PropertyAccessor::isReadable()``
## Usage Example
``` twig
{# table.html.twig #}
{% block table %}
{% for col in control.columns %}
{{ col|trans }} |
{% endfor
{% for row in control.rows %}
{% for col in control.columns %}
{{ has_property(row, col) ? property(row, col) : block(col) }}
|
{% endfor %}
{% endfor
{% endblock %}
``` twig
{# index.html.twig #}, (*9)
{% extends 'base.html.twig' %}, (*10)
{% use 'table.html.twig' %}, (*11)
{% block body %}
{% control table with {
columns: ['name', 'user.email', 'special_column'],
rows: entities
} %}
{% endblock %}, (*12)
{% block special_column %}
edit
{% endblock %}
```, (*13)