You have to create a custom template for the field you want to customise the rendering.
For your status
field, create a template like this :
// src/AcmeBundle/Resources/views/CRUD/status_field.html.twig
{% extends 'SonataAdminBundle:CRUD:base_list_field.html.twig' %}
{% block field %}
{% set status = object.status == 1 ? 'success' : 'danger' %}
<div>
<span class="label label-{{ status }}">{{ object.status }}</span><br />
</div>
{% endblock %}
Configure it as template in your admin class :
$listMapper
// ...
->add('status', null, array(
'template' => 'AcmeBundle:CRUD:status_field.html.twig'
))
Explained in the little but helpful part of the documentation .
I actually tested with the sonata admin Bundle version 2.3.3, and it's as easy as this:
/**
* @param ListMapper $listMapper
*/
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->add('status', 'boolean');
}
in your admin class.
The custom template works but it is not necessary in this case as it already implemented. The vendor template is located in vendor/sonata-project/admin-bundle/Resources/views/CRUD/list_boolean.html.twig
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.