Zhi V
Zhi V

Reputation: 364

DetalView Yii2: how to output text with html tags

I use DetalView widget and I need <ВR> tag:

<?= DetailView::widget([
        'model' => $model,
        'attributes' => [
            'information:ntext',                
            [
                'attribute' => 'text',
                'value' => $model->getUserAttributes('getScientificWorks', 'text'),
            ],
         ],
    ])
    ?>

getUserAttributes returns string:

$string .= $item[$field] . ", ";

If instead of comma input <ВR>, then text will be like this: "text.. <ВR> ..text"

Upvotes: 2

Views: 3652

Answers (3)

Nawin
Nawin

Reputation: 1692

You can use $string .= nl2br($item[$field]).

Upvotes: 0

Nikko Madrelijos
Nikko Madrelijos

Reputation: 545

Try this

...........

    [
        'attribute' => 'text',
        'value' => $model->getUserAttributes('getScientificWorks', 'text'),
        'format' => 'raw',
    ],

............

The "raw" format tells Yii2 not to do anything with the output. So it will display any html tag.

Upvotes: 5

GAMITG
GAMITG

Reputation: 3818

You need to try to use format property like as 'formate' => 'text'.

  ........
        [
            'attribute' => 'text',
            'value' => $model->getUserAttributes('getScientificWorks', 'text'),
            'format' => 'text',
        ],
  .........

Upvotes: 1

Related Questions