Get Off My Lawn Get Off My Lawn - 3 months ago 10
PHP Question

Laravel DataTable plugin is outputting code with htmlentities

I am using this DataTable plugin for Laravel, which is for using This jQuery DataTable plugin.

I Followed the instructions found here, so this is my controller:

class FeedbackController extends Controller {

public function UserFeedback(Request $request) {
$t = Datatable::make(new CollectionProvider(FeedbackModel::all()))
->column('overall')
->build();

if ($t->shouldHandle()) {
return $t->handleRequest();
}

return view('admin.feedback', ['datatable' => $t->view()]);
}

}


And this is in my view:

{{
$datatable->html()
}}


But for some reason when I load the page it is outputting the html with htmlentities like this:

<table id="dataTable">
</table><script type="text/javascript">
jQuery(document).ready(function () {
// dynamic table
oTable = jQuery('#dataTable').DataTable({
"processing": true,
"serverSide": true,
"ajax": "/",
"columns": [
{ 'data': 'overall' },
]
});
});
</script>


Why is it doing this?

Answer

This will help you (taken from laravel docs)

Displaying Raw Text With Curly Braces

If you need to display a string that is wrapped in curly braces, you may escape the Blade behavior by prefixing your text with an @ symbol:

@{{ This will not be processed by Blade }}

If you don't want the data to be escaped, you may use the following syntax:

Hello, {!! $name !!}.

Use that on this...

{{
    $datatable->html()
}}

Ignore the above, that is the wrong way around, do the below...

Or

You can decode the html like this...

htmlspecialchars_decode($datatable->html())

and output that...

Comments