Hello. Can you please tell me how to implement the truncate function in the DetailView widget? In GridView figured out, like so did:

<?= GridView::widget([ 'dataProvider' => $dataProvider, 'columns' => [ ['class' => 'yii\grid\SerialColumn'], [ 'attribute' => 'description', 'options' => ['style' => 'height:200px'], 'value' => function ($model) { return StringHelper::truncate($model->description, 300); } ], 

Everything worked, but if you do this in the DetailView, it does not work. Error writes.

    1 answer 1

    In DetailView you need to send not the callback , but the attribute value itself.

    For example:

     'value' => StringHelper::truncate($model->description, 300) 
    • Exactly what is needed. Thank you very much! - Alexey