How do I pass the $styles and $scripts variables to my template view file from IndexController that calls a child view? My current code will only send the data to child view.
class BaseController extends Controller
{
public $styles;
public $scripts;
public function __construct()
{
// Set styles and scripts
$this->styles = array(
// css files go here
);
$this->scripts = array(
// js files go here
);
}
}
class IndexController extends BaseController
{
// protected vars here
public function __construct(
// interface files go here
)
{
// vars here
// Append styles and scripts to existing parent array
parent::__construct();
$this->styles['css goes here'] = 'screen';
$this->scripts[] = 'js goes here';
}
public function index()
{
View::make('index')->with('styles', $styles)
->with('scripts', $scripts)
}
}
UPDATE: Added my view files
Template view file
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="index, follow" />
<title>Title</title>
@foreach($styles as $file => $type)
<link href="{{ $file}}" media="{{ $type }}" rel="stylesheet">
@endforeach
@foreach($scripts as $file)
<script src="{{ $file }}"></script>
@endforeach
</head>
<body>
<div id="content">
{{ $content }}
</div>
</body>
</html>
Child view file
@extends('layout.template')
@section('content')
// html for child view
@endsection