Yii2: How to get a new line in a Gridview column

Created on 25 Jun 2016  路  3Comments  路  Source: yiisoft/yii2

What steps will reproduce the problem?

I am traing to display two attributes in a single GridView::widget column, with a new line in between them.
Below is the code, but the "\n". or br tag is not converting into new line. Is there any alternative way?
[ 'label' => 'Message', 'attribute' => 'message', 'value' => function ($searchModel) { return Yii::$app->formatter->asNtext($searchModel->message)."\n".Yii::$app->formatter->asDatetime($searchModel->sent_time); }, ],

What is the expected result?

New Line in between attribute values

What do you get instead?

No new line in between attributes

Additional info

| Q | A |
| --- | --- |
| Yii version | Latest |
| PHP version | 7 |
| Operating system | Linux |

Thank you for your help

question

Most helpful comment

@cebe Thank you for your help.
'format' => 'html', with a <br> tag fixed the issue.

All 3 comments

the output will be html so you should use a <br> instead of \n.

_This is an automated comment, triggered by adding the label question._

Please note, that the GitHub Issue Tracker is for bug reports and feature requests only.

We are happy to help you on the support forum, on IRC (#yii on freenode), or Gitter.

Please use one of the above mentioned resources to discuss the problem.
If the result of the discussion turns out that there really is a bug in the framework, feel free to
come back and provide information on how to reproduce the issue. This issue will be closed for now.

@cebe Thank you for your help.
'format' => 'html', with a <br> tag fixed the issue.

Was this page helpful?
0 / 5 - 0 ratings