0

I've been trying to convert a php variable into a java script variable. At the same time I want to save it in a format with HTML tags. The problem is I'm Unable to escape the '<' this character in code.

 var lecturers = [
     @foreach ($Lecturers as $L)
       '{{ '<option>'.$L->Name.'</option>' }}',
     @endforeach
 ];

The Output I received through console log is as follows

["&lt;option&gt;&lt;/option&gt;", "&lt;option&gt;&lt;/option&gt;", "&lt;option&gt;&lt;/option&gt;"]

How can i get the output as

"<option> Name </option>"

I'm using laravel as Framework.

1 Answer 1

1

You have to use {!! !!} instead to avoid escaping:

var lecturers = [
     @foreach ($Lecturers as $L)
       '{!! '<option>'.$L->Name.'</option>' !!}',
     @endforeach
 ];
Sign up to request clarification or add additional context in comments.

1 Comment

That was brilliant. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.