Customizing DetailedView widget depending on attribute value

Hello,

I am currently working with the yii\widgets\DetailView and need to define the style an attribute needs to take depending on the value the attribute takes. My widget is set as follows




<?=


    DetailView::widget([

        'model' => $model,

        'attributes' => [

            'attributeX',

            [

                'label' => Yii::t('app', 'attributeY'),

                'value' => function ($model, $widget){

                    $pLang = \common\models\Language::findOne(['id'=>$model->preferred_language_id]);

                    $str = Yii::t('app','(not set)');

                    if($pLang != null){

                        $str = $pLang->name;

                    }

                    return $str;

                },

            ],

            

        ],

    ])

    ?>



What i need is to define a style or class to attributeY if $pLang is null. How could i go about doing this?

thanks in advance for your help

hope this helps




<?=

$pLang = \common\models\Language::findOne(['id'=>$model->preferred_language_id]);

DetailView::widget([

    'model' => $model,

    'attributes' => [

        'attributeX',

        [

            'label' => Yii::t('app', 'attributeY'),

            'value' => '<span class="plang">' . ($pLang != null ? $pLang->name : Yii::t('app','(not set)')) . '</span>',

            'format' => 'html'

        ],

    ],

])

?>

yes using the ‘format’ option was the solution

Thanks!