tmilos / symfony-control
Installs: 12
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Type:bundle
Requires
- symfony/config: ~2.3|~3.0
- symfony/dependency-injection: ~2.3|~3.0
- symfony/http-kernel: ~2.3|~3.0
- symfony/property-access: ~2.3|~3.0
- twig/twig: ~1.20|~2.0
Requires (Dev)
- phpunit/phpunit: ^4.8
- satooshi/php-coveralls: ~0.6
This package is not auto-updated.
Last update: 2024-11-09 19:23:41 UTC
README
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 %}