S
S
Sergey2016-07-27 01:03:17
JavaScript
Sergey, 2016-07-27 01:03:17

How in yii2 in view to display data only if it exists?

Hello. I pass an array to the view and show the data in some places from it.
There may be no data in the elements, how then not to show part of the view file?
For example, this code:

<? if (!empty($theuserinvoice['phone'])) { ?>
  <span class="labelo">Phone: </span> <?=$theuserinvoice['phone']?> <br/>
<? } ?>

It still shows "Phone:" as a result. The same goes for these pieces:
<? if ($theuserinvoice['phone'] != '') { ?>
  <span class="labelo">Phone: </span> <?=$theuserinvoice['phone']?> <br/>
<? } ?>

// или

<? if ($theuserinvoice['phone'] != NULL) { ?>
  <span class="labelo">Phone: </span> <?=$theuserinvoice['phone']?> <br/>
<? } ?>

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Arthur, 2016-03-07
@astralo

Nikolai Petyukh hahaha))) your categoricalness is amazing. after all, you don’t know what kind of markup is there, but you express it this way)) and in his case it is quite possible that the element is dynamic, and then Ivan Kondratiev is right))
And in fact, if the element is added dynamically, then the client event is not yet fixed to it. the code

$(document.body).on('click','.responsesimilar', function(){
  console.log(this);
});

solves this problem.
well, yes, it would be nice to add event.preventDefault(); to cancel the default action of the link, i.e. go to the address specified in href

S
Sergey, 2016-07-27
@butteff

the problem was short_open_tags. Thanks everyone for the help

N
Nazar Mokrinsky, 2016-07-27
@nazarpc

Do var_dump($theuserinvoice['phone'])it and see what really lies there, only then you can draw conclusions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question