laravel 5.3 how to render html content of a page in a view with a function
I am facing a rendering problem...
in my product.blade.php I would like to show in a part of the page the html content from an external source without iframe.
I want to make a call like :
In the controller, get the remote content and assign it to a variable. Use Curl, Guzzle or just fileGetContents. Stick with a fixed ID to start with
just return or dd() the variable and check its fetching something.
Get the ID from the request and check the controller correctly fetches variable content depending on the ID requested
Create the view and inject the content using {!! blade tags if you trust the content (dangerous) as this will render exactly what you grabbed. Bear in mind that links and img references in the content are likely to be broken
In the controller return View with the variable you assigned the content to
Consider caching the data fetched for a short time.
Thanks for your help.
I just tried to dd() the variable, it doesn't work... I may not do the right thing regarding this.
Shall I delete this in my product page, to make it simple :
{!! View::make('pages.viewer', ['docUrl' => url('get-DocHtml/' . $primaryAttachment->id)]) !!}
And delete in my route : Route::get('get-DocHtml/{id}', 'PagesController@getDocHtml');
Can I just have a call like {!! $external !!} (I have an error "Method Illuminate\View\View::__toString() must not throw an exception")
and use a function with variable like this in my PagesController.php :
public function getDocHtml($id)
{ $attachment = Attachment::find($id);
$filepath = Storage::disk('S3')->url($attachment->filename.'/test.html'); $file = file_get_contents($filePath)
return Viewe::make('pages.viewer', ['external' => $file]);
How can I have in my product page this html content ?
Thanks for your first answer. Everything is working. I actually change my controller as my variable was empty with the right function
$filepath = Storage::disk('S3')->url($attachment->filename.'/test.html'); $file = file_get_contents($filePath)
return view('pages.product')->withExternal($file);
and in my product blade, I just have a {!! $external !!}