In the edit method instead of
return View::make('tests.edit')->with(array('course'=>$course));
use:
$this->layout->content= View::make('tests.edit')->with(array('course'=>$course));
Question
My template layout blade doesn't render when the url is a subfolder.
I made a test example to check:
URL/tests is okay
but
URL/tests/1/edit loses the outer layout template and only renders the content.
Testcontroller:
class TestController extends AdminController {
protected $layout = 'layouts.admin';
public function index()
{
// load the view
$this->layout->content=View::make('tests.index');
}
public function edit($id)
{
//
$course=Course::find($id);
return View::make('tests.edit')->with(array('course'=>$course));
}
}
layout admin.blade.php
<html><body>
{{ $content }}
</body>
</html>
tests/index.blade.php
hello
/tests renders source full layout html code and works fine on proper site examples
tests/edit.blade.php
edit
/tests/1/edit renders with NO layout HTML
There are various ways of using blade but I thought the easiest was with protected layout but there seem to be issues?
Any help appreciated.
Solution
In the edit method instead of
return View::make('tests.edit')->with(array('course'=>$course));
use:
$this->layout->content= View::make('tests.edit')->with(array('course'=>$course));
OTHER TIPS
In your AdminController
which is the base controller of your TestController
, add the layout setings, put this code in your AdminController
protected $layout = 'layouts.master';
protected function setupLayout()
{
if ( ! is_null($this->layout))
{
$this->layout = View::make($this->layout);
}
}
Now you use any view with layout using something like this:
$this->layout->content = View::make('tests.edit')->with(array('course'=>$course));
Here, tests.edit
means that edit.blade.php
(also could edit.php
if not blade) file is in app/views/tests/
directory.
In your index
method you have used:
$this->layout->content=View::make('tests.index');
So the layout
showed up because you set data to layout but in other example you didn't set data to layout
so layout is not rendered, it's returning only the view as given below:
return View::make('tests.edit')->with(array('course'=>$course));
So, setup the layout in the base controller class so in your every controller you don't have to setup the layout, but always set data to the content
variable of layout using this:
$this->layout->content = 'your data';