How would I pass an array of variables to SonataMediaBundle:MediaAdmin:list_image.html.twig
?
There does not seem to be any option available.
class MediaAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('image', 'string', array(
'template' => 'SonataMediaBundle:MediaAdmin:list_image.html.twig',
array('data'=>'something')<<- This is not working
))
->add('custom', 'string', array(
'template' => 'SonataMediaBundle:MediaAdmin:list_custom.html.twig'
))
;
}
}
Template:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field%}
{{dump(data)}} <<- This is not working
{% endblock %}
I just want to pass a variable value to SonataMediaBundle:MediaAdmin:list_image.html.twig
.
Just elaborating Tigran's answer.
class MediaAdmin extends Admin
{
public $data = '';
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('custom', 'string', array('template' => 'SonataMediaBundle:MediaAdmin:list_custom.html.twig'))
;
$this->data = 'something';
}
}
and in your template:
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
<div>
{{ admin.data }}
</div>
{% endblock %}
and if you have an array indexed by object's id, you can access it this way:
{{ attribute( admin.data, object.id) }}
class MediaAdmin extends Admin
{
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('image', 'string', array('template' => 'SonataMediaBundle:MediaAdmin:list_image.html.twig','data'=>'something'))
->add('custom', 'string', array('template' => 'SonataMediaBundle:MediaAdmin:list_custom.html.twig'))
;
}
}
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
{{field_description.options.data}}
{% endblock %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With