Skip to content

Instantly share code, notes, and snippets.

@beanmoss
Created April 18, 2015 04:45
Show Gist options
  • Save beanmoss/81b7d020a0db4e7ce7f4 to your computer and use it in GitHub Desktop.
Save beanmoss/81b7d020a0db4e7ce7f4 to your computer and use it in GitHub Desktop.
LARAVEL: Displaying different module/package dashboard widgets using view composers.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Laravel PHP Framework</title>
<style>
@import url(//fonts.googleapis.com/css?family=Lato:700);
body {
margin:0;
font-family:'Lato', sans-serif;
text-align:center;
color: #999;
}
h1 {
font-size: 32px;
margin: 16px 0 0 0;
}
</style>
</head>
<body>
<div>
@section('widgets')
@show
</div>
</body>
</html>
<?php
Route::get('/dashboard', function()
{
return View::make('dashboard');
});
// Located on other module/package
View::composer('dashboard', function($view)
{
$view->nest('widget1-section', 'widget1');
});
// Located on other module/package
View::composer('dashboard', function($view)
{
$view->nest('widget2-section', 'widget2');
});
// Located on other module/package
View::composer('dashboard', function($view)
{
$view->nest('widget3-section', 'widget3');
});
//Probably on another module/package
@section('widgets')
@parent
@section('widget1-section')
<h1>Widget One</h1>
@show
@stop
//Probably on another module/package
@section('widgets')
@parent
@section('widget2-section')
<h1>Widget Two</h1>
@show
@stop
//Probably on another module/package
@section('widgets')
@parent
@section('widget3-section')
<h1>Widget Three</h1>
@show
@stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment