14

That's how I am rendering the values on a grid view

enter image description here

but instead of links I can see the textual value.

enter image description here

How can I make it render html instead of text?

3 Answers 3

30

In link column configuration add:

'format' => 'html',

or if you want some extra markup there

'format' => 'raw',

In case of raw remember to encode values coming from outside users because it's not done automatically.

Sign up to request clarification or add additional context in comments.

2 Comments

where are this 'format' configuration documented? i can't find it anywhere. in api doc there is only one example without explanation
It's mentioned here and examples can be found here.
3

A better way of doing this in Yii.

'value' => function ($data) {
    return Html::a($data->name, [$data->url, 'someData' => $data->someData]);
}

Yii Doc: https://www.yiiframework.com/doc/api/2.0/yii-helpers-basehtml#a()-detail

A little late on the post but, hope it helps the in future.

Comments

2
<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yii\grid\SerialColumn'],
        'name',
        'email:email',
        'timestamp:date',
        [
            'attribute'=>'Resume',
            'format' => 'raw',
            'class' => 'yii\grid\DataColumn', // can be omitted, as it is the default
            'value' => function ($data) {
                $url = "www.sample.com/contactform/resumes".$data->resumepath;
                return Html::a('<i class="glyphicon glyphicon-download-alt"></i>', $url);
            },
        ],

        ['class' => 'yii\grid\ActionColumn'],
    ],
]); ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.