When templating in Laravel I'm aware of how to have a master template and define the individual content areas in each view file, but if I have a snippet of template code I want to include at certain points in my view files how would I do this?
To clarify, say I have a few views with a form in them. One might look like this:
@section('content')
<h3>Login</h3>
{{ Form::open(array('url' => 'login')) }}
<!-- if there are login errors, show them here -->
@if ( count($errors->all()) )
<div class="alert alert-danger">
<p>Some validation errors occurred:</p>
<ul>
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<div class="form-group">
{{ Form::label('email', 'Email Address') }}
etc...
As you can see there is an if
statement checking for validation errors. This block is something I might want on many forms around my site but it seems bad practice to copy-paste the whole block across template files. Is there a way to store it in, say, a views/components.blade.php
file and yield that particular block when required?