【问题标题】:Has Blade Templating Changed from Laravel 4 to Laravel 5?刀片模板是否从 Laravel 4 更改为 Laravel 5?
【发布时间】:2016-02-02 06:55:22
【问题描述】:

问题:将我的 Laravel 4 代码转换为 Laravel 5。@section('container') 和 @stop 之间的屏幕上没有任何内容。

注意事项:我正在使用 Laravel Collective HTML Facades。为简洁起见,我已经严重缩短了 master.blade.php 文件。

请求:请协助找出浏览器中没有显示任何内容的原因,并在可能的情况下详细告诉我我在示例中做错了什么。

错误和调试:没有。页面是空白的。

尝试:如果我在@section('container') & @stop 之外添加任何内容,那么它会显示在屏幕上。

composer.json

"require": {
    "php": ">=5.5.9",
    "laravelcollective/html": "5.2.*"
},

app.php

Providers Array
        Collective\Html\HtmlServiceProvider::class,

Alias Array
        'Form'      => Collective\Html\FormFacade::class,
        'Html'      => Collective\Html\HtmlFacade::class,

ma​​ster.blade.php

  <body>
        <!--[if lt IE 7]>
            <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
        <![endif]-->

        <!-- Add your site or application content here -->
        @yield('container')
    </body>

index.blade.php

 @section('container')
  <!--[if gte IE 9]>
  <style type="text/css">
    .gradient {
       filter: none;
    }
  </style>
<![endif]-->
<div style="margin: 10px 0 0 20px;border: 0px black dashed;width: 410px;float:left;">
        {!! Form::open(array('action' => 'ContractController@store')) !!}
        {!! Form::token() !!}
<dl style="list-style-type:none;">
    <fieldset>
        <legend>General Information</legend>
            <dd>
                {!! Form::label('contractterm','Contract Term', array('class' => 'label')) !!}
                {!! Form::select('contractterm_id', $contracttermlist) !!}
            </dd>
            <dd>
                {!! Form::label('businesstype','Business Type', array('class' => 'label')) !!}
                {!! Form::select('businesstype_id', $businesstypelist) !!}
            </dd>
            <dd>
                {!! Form::label('contract_date','Contract Starting Date', array('class' => 'label')) !!}
                {!! Form::text('contract_date', date('m/d/Y'), array(
                    'size'=>'16',
                    'id' =>'datepicker'))
                !!}
            </dd>
            <dd>
                {!! Form::label('service_credit','Previous Service', array('class' => 'label')) !!}
                <div style="float:right;width:140px;height:29px;"><span>Yes</span><span style="float:right;width:20px;padding-top:4px;padding-right:90px;">{!! Form::checkbox('prevcredit', 'credityes', false, array('class' => 'creditcheckbox','id' => 'prevcredit')); !!}</span></div>
            </dd>
            <dd>
                {!! Form::label('credit_amount','Credit Amount', array('class' => 'label','id' => 'credit_amount')) !!}
                {!! Form::text('credit_amount','0.00',array('id' => 'credit_amount2')) !!}
            </dd>
            <dd>
                {!! Form::label('addtpcs','Additional PCs', array('class' => 'label')) !!}
                {!! Form::select('addtpcs', $addtpcs) !!}
            </dd>
            <div id="inputs" style="margin:0;">
            </div>
    </fieldset>
    <fieldset>
        <legend>Personal Information</legend>
            <dd>
                {!! Form::label('firstname','First Name', array('class' => 'label')) !!}
                {!! Form::text('firstname') !!}
            </dd>
            <dd>
                {!! Form::label('lastname','Last Name', array('class' => 'label')) !!}
                {!! Form::text('lastname') !!}
            </dd>
            <dd>
                {!! Form::label('hstraddr','Home Address', array('class' => 'label')) !!}
                {!! Form::text('hstraddr') !!}
            </dd>
            <dd>
                {!! Form::label('hcity','Home City', array('class' => 'label')) !!}
                {!! Form::text('hcity') !!}
            </dd>
            <dd>
                {!! Form::label('hstate','Home State', array('class' => 'label')) !!}
                {!! Form::text('hstate', 'Florida') !!}
            </dd>
            <dd>
                {!! Form::label('hzip','Home Zip Code', array('class' => 'label')) !!}
                {!! Form::text('hzip') !!}
            </dd>
            <dd>
                {!! Form::label('hphone','Home Phone', array('class' => 'label')) !!}
                {!! Form::text('hphone') !!}
            </dd>
            <dd>
                {!! Form::label('mobile','Mobile Phone', array('class' => 'label')) !!}
                {!! Form::text('mobile') !!}
            </dd>
    </fieldset>
    <fieldset>
        <legend>Business Information</legend>
            <dd>
                {!! Form::label('company','Company Name', array('class' => 'label')) !!}
                {!! Form::text('company') !!}
            </dd>
            <dd>
                {!! Form::label('bstraddr','Business Address', array('class' => 'label')) !!}
                {!! Form::text('bstraddr') !!}
            </dd>
            <dd>
                {!! Form::label('bcity','Business City', array('class' => 'label')) !!}
                {!! Form::text('bcity') !!}
            </dd>
            <dd>
                {!! Form::label('bstate','Business State', array('class' => 'label')) !!}
                {!! Form::text('bstate', 'Florida') !!}
            </dd>
            <dd>
                {!! Form::label('bzip','Business Zip', array('class' => 'label')) !!}
                {!! Form::text('bzip') !!}
            </dd>
            <dd>
                {!! Form::label('bphone','Business Phone', array('class' => 'label')) !!}
                {!! Form::text('bphone') !!}
            </dd>
            <dd>
            <div class="submitbutton">
                    {!! Form::submit('Submit') !!}
            </div>
            </dd>
    </fieldset>
</dl>
        {!! Form::close() !!}
</div>
<div style="clear:both;"></div>
@stop

IndexController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Library\additionalPCs;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use View;
use App\Models\businesstype;
use App\Models\contractterm;


class IndexController extends BaseController
{
    Protected $layout = 'master';
    /**
     * Display a listing of the resource.
     *
     * @return Response
     */
    public function index()
    {
        /** Wayne - 03-02-2014 - Moved for loop to a method within its own class. */
        $numberofpcs = new additionalPCs();
        $addtpcs=$numberofpcs->display();
        //$this->layout->content = View::make('index')->with('addtpcs', $addtpcs)->with('businesstypelist', businesstype::dropdown())->with('contracttermlist',ContractTerm::dropdown());
        return view('index')->with('addtpcs', $addtpcs)->with('businesstypelist', businesstype::dropdown())->with('contracttermlist',ContractTerm::dropdown());
    }
}

【问题讨论】:

    标签: laravel laravel-5 blade laravel-5.2 laravel-blade


    【解决方案1】:

    在您的 index.blade 文件中,您似乎缺少应该出现在最顶部的扩展标签,然后是您的 @section 代码

    @extends('master')
    @section('container')
       your section code here
    @stop
    

    【讨论】:

    • 谢谢卢查。这解决了这个问题。对于正在阅读本文的任何人,请查看 Jeff 的答案。从 Laravel 5.1 开始,stop 被 endsection 取代。相应地更新您的代码。
    【解决方案2】:

    现在是 @section('container'),然后是 @endsection,而不是 Laravel 5.1 中的 @stop

    https://laravel.com/docs/5.1/blade#template-inheritance

    【讨论】:

    • 感谢您告诉我。我已将该停止更新到结束部分,并将更新其余的刀片模板。不幸的是,这并没有解决问题。 Lucha 的回答解决了有或没有 endsection 或 stop 的问题。
    猜你喜欢
    • 2019-12-02
    • 2013-05-08
    • 2013-04-29
    • 2015-04-16
    • 1970-01-01
    • 2014-11-19
    • 2016-12-18
    • 2017-04-03
    相关资源
    最近更新 更多