unexpected endforeach in blade template

岁酱吖の 提交于 2019-12-12 15:12:18

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!