Upgrading Laravel 5.2 to 5.3 with hidden comment code

72 views Asked by At

I am updating a site from Laravel 5.2 to (eventually) 5.7 that was coded by someone else.

Currently I having an issue with this type of code in a blade file:

{{-- */ $hidden = 'hidden' /* --}}

That creates a variable that is used in the file itself like this:

<div class="col-xs-2 {{$hidden}}" id="person1div">
    &nbsp;
</div>

That seems to work fine in Laravel 5.2 but in 5.3 I get the error message:

Undefined variable: hidden

I could change the code to

<?php $hidden = 'hidden' ?>

but the issue is that there are many variables like this, used in various ways.

Something to note is that these variable are in loops which I guess is why the original developer used them as they get reset and re-populated.

Is there a more correct way to populate the variables?

2

There are 2 answers

2
Himanshu Upadhyay On BEST ANSWER

You can select and replace the syntax like shown below.

You can set variables with values in blade file like this:

@php $hello = "Hello World!"; @endphp

and to print the variable on the blade file,

{{$hello}}
0
Mhluzi Bhaka On

Right, solved this (as often happens on SO) just after I posted this question.

I did a global find and replace and changed instances of

{{-- */

to

{!!

and also

/* --}}

to

!!}

So instead of

  {{-- */ $hidden = 'hidden' /* --}}

I have:

  {!! $hidden = 'hidden' !!}

That has done the trick.

Thanks for the answers - hope this helps someone else.

EDIT***********************************

Although I thought this was going to work for me as it turns out I kept on getting errors such as "Array to string conversion"

So I am going ahead with the answer from @himanshu-upadhyay