问题
I have a blade
template in laravel
in laravel that displays a tab view. The tabs are different eventtypes
and in the tabs are the events
per type. This view worked fine until today. The only thing that changed is that I made it possible to soft-delete events
.
The error I get is the following:
syntax error, unexpected 'endforeach' (T_ENDFOREACH)
This is the entire source code of the template:
@extends('master')
@section('title', '- Kalenderbeheer')
@section('head')
{{ HTML::script('Script/lib/dataTables.js'); }}
<script>
$(document).ready(function(){
$("#EventTypeTabs").tab();
$(".eventtable").dataTable({
paging: false,
info: false,
"aoColumns": [
null,
null,
null,
{ "asSorting": [] }
]
});
$(".eventtable tr").click(function(){
if ($(this).data("id"))
location.href = "/kalender/admin/" + $(this).data("id");
})
});
</script>
@stop
@section('body')
<div class="row">
<div class="col-md-6 col-md-offset-1">
<h1>Kalenderbeheer</h1>
</div>
<div class="col-md-4 rtl">
<a href="/kalender/admin/nieuw">Nieuwe activiteit toevoegen</a>
</div>
</div>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<ul class="nav nav-tabs" style="margin-bottom: 15px;" id="EventTypeTabs">
@foreach ($eventtypes as $et)
<li @if($et->id == 1) class="active" @endif>
<a href="#{{{ $et->getFormattedName() }}}" data-toggle="tab">{{{ $et->name }}}</a>
</li>
@endforeach
</ul>
<div class="tab-content eventtypetabs">
@foreach ($eventtypes as $et)
<div class="tab-pane fade @if ($et->id == 1)active in@endif" id="{{{ $et->getFormattedName() }}}">
@if (count($et->events) > 0)
<table class="table table-striped eventtable">
<thead>
<tr>
<th>#</th>
<th>Datum</th>
<th>Naam</th>
<th></th>
</tr>
</thead>
<tbody>
<?php $c = 0; ?>
@foreach ($et->events as $event)
<tr data-id="{{ $event->id }}">
<td>{{ ++$c }}</td>
<td>{{ preg_replace("/\d{2}:\d{2}:\d{2}/", "", $event->start) }}</td>
<td>{{{ $event->name }}}</td>
<td>X</td>
</tr>
@endforeach
</tbody>
</table>
@endif
</div>
@endforeach
</div>
</div>
</div>
@stop
The error appears on the last @endforeach
. This is a screenshot of the error:

回答1:
You just need to add a space before @endif (line 48)
<div class="tab-pane fade @if ($et->id == 1)active in @endif" id="{{{ $et->getFormattedName() }}}">
Also, it's better to use the ternary operator:
class="tab-pane fade {{ $et->id == 1 ? 'active in' :''}}"
来源:https://stackoverflow.com/questions/24184925/unexpected-endforeach-in-blade-template