So there's this method available on the View facade that does something pretty neat.
This method is called renderSections()
Accessing this method goes a little bit like this:
// Make view, with variable for example
$view = View::make('path.to.view')->with('name', 'JohnDoe');
return $view->renderSections()
Before we take a look at what this returns us, we must first look at our application layout.
If we have this for example:
<html>
<body>
<div>@yield('content')</div>
@section('sidebar')
@show
</body>
</html>
Our renderSections() method will return us an array of the content we filled these sections with, for example:
array (size=2)
'content' => string ' <div class='left well pull-left'>
<h2>Sheikh Heera</h2>
<p>Contact: 0123456789</p>
</div>
' (length=100)
'sidebar' => string ' <div class='right well pull-right'>
<h1>Sidebar</h1>
<u>
<li>ListOne</li>
<li>ListTwo</li>
<li>ListThree</li>
</ul>
</div>
' (length=148)
So, we can effectively build our html string for use with ajax like so :
if(Request::ajax()) {
$view = View::make('card');
$view = $view->renderSections();
return join($view, '');
}
This seem awesome, I'll definitely take a look at renderSection. Thanks a lot.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community