M
M
Michael2019-12-03 22:23:01
Yii
Michael, 2019-12-03 22:23:01

How to resolve syntax error, unexpected 'if' (T_IF) error?

Hello everybody! Please tell me, when using Menu::widget in one of the menu items, it is required to display the counter by condition, I wrote as follows:

[
    'label' => 'Интернет-приемная',
    'icon' => 'envelope-o',
    'url' => ['/mailbox'],
    'template'=>'<a href="{url}">{icon} {label}<span class="pull-right-container"><small class="label pull-right bg-yellow">' . if($count){echo $count}; . '</small></span></a>',
],

but in this case I get an error ParseError syntax error, unexpected 'if' (T_IF).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mitaichik, 2019-12-04
@mitaichik

....bg-yellow">' . ($count ?: '') . '</sma....

L
Lander, 2019-12-04
@usdglander

if is an operator, not a function, so it does not return a value and therefore cannot be concatenated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question