Skip to content

Commit 0015b1d

Browse files
author
Tortue Torche
committed
The Controller::render() method can now renders inline text.
E.G. rendering inline javascript inside a controller action: public function create() { $message = new App\Message; $formId = form_id($message); $html = json_encode(render_view("messages.form", compact('message'))); $this->render(['js' => "MessagesView.create('$formId', $html)"]); }
1 parent a843738 commit 0015b1d

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/Efficiently/JqueryLaravel/ControllerAdditions.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php namespace Efficiently\JqueryLaravel;
22

3-
use View;
3+
use Blade;
44
use Request;
55
use Response;
66

@@ -21,12 +21,17 @@ public function render($view, $data = [], $layout = null)
2121
if (is_array($view) && count($view) === 1) {
2222
$format = array_keys($view)[0];
2323
$view = array_values($view)[0];
24-
if (! ends_with($view, '_'.$format)) {
25-
$view = $view.'_'.$format;
24+
if (is_string($view)) {
25+
if (! ends_with($view, '_'.$format) && view()->exists($view.'_'.$format)) {
26+
$view = $view.'_'.$format;
27+
} else {
28+
// inline view
29+
$view = Blade::compileString($view);
30+
}
2631
}
2732
}
2833

29-
if (is_string($view)) {
34+
if (is_string($view) && view()->exists($view)) {
3035
$view = view($view, $data);
3136
}
3237

0 commit comments

Comments
 (0)