Give it a try and see.
Get file_get_contents of a View.
Hi,
Is there an easy way via Laravel to do a file_get_contents() of a view so it can be rendered in a textarea for manipulation? Some frameworks such as code ignitor allow you to receive the view's source code without rendering it.
I tried $html = View::make('admin.templates.show')->render() without success, but think the render is probably throwing it off track and causing errors? Would a file_get_contents be the answer? e.g something like.
$html = file_get_contents('\resources\views\admin\templates\show.blade.php');
Thanks,
MoFish
@MoFish you should use absolute paths when you want to work with files. file_get_contents() is fine. There are some file wrappers available in laravel but internally they all use file_get_contents().
Try:
file_get_contents(resource_path('views/admin/templates/show.blade.php'));
resource_path() is one of the many helper functions of Laravel. It gives you the absolute path to your resources directory. See https://laravel.com/docs/5.5/helpers#method-resource-path for more methods like this.
Please or to participate in this conversation.