Dython
Dython

Reputation: 134

php laravel - how to pass controller output to view as iframe source

I have a controller which gives output as URL , now I want to pass the output url to view and below is the code.But when I load the view I found that iframe is not loading and the url is showing in the body of the html.

inside controller this is how I am returning the output

 return view('ifr',['name' => $url]);

And this is my view code

<iframe src={{$name}}></iframe>

Could you please help me with the correct syntax

Upvotes: 2

Views: 7986

Answers (2)

Andrius Rimkus
Andrius Rimkus

Reputation: 653

Instead of <iframe src={{$name}}></iframe>

Try <iframe src={!! $name !!}></iframe>

More at: https://laravel.com/docs/5.4/blade / Displaying Unescaped Data

Upvotes: 4

Rahul Chauhan
Rahul Chauhan

Reputation: 1554

Pass the iframe src in single quotes

Like

$src = '"https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2Fhierensolanki%2Fposts%2F1264241026994313&width=500" width="500" height="608" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"';

return view('welcome',compact('src'));

And in your view file.

<iframe src=<?php echo $src; ?>></iframe>

It will work.

Upvotes: 1

Related Questions