LaravelでBladeの記述形式で@sectionや@yieldで継承を用いた画面を作っているのですが、
子の画面の内容だけがが上手く表示されず下記画面のようになっております。
Laravelに詳しい方がいらっしゃいましたら
よろしくお願いいたします。
以下ソースコードになります。
●laravelapp\routes\web.php <?php Route::get('/', function () { return view('welcome'); }); Route::get('hello/','Hellocontroller@index');
●laravelapp\resources\views\hello\index.blade.php(子画面) @extends('layouts.helloapp') @section('title', 'index') @section('menubar') @parent インデックスページ @endsection @section('content') <p>ここが本文のコンテンツです。</p> <p>必要なだけ記述できます。</p> @endsection @section('footer') copyright 2017 tuyano. @endsection
●laravelapp\resources\views\layouts\hello.blade.php <html> <head> <title>@yield('title')</title> <style> body {font-size:16pt; color:#999; margin: 5px; } h1 { font-size:50pt; text-align:right; color:#f6f6f6; margin:-20px 0px -30px 0px; letter-spacing:-4pt; } ul { font-size:12pt; } hr { margin: 25px 100px; border-top: 1px dashed #ddd; } .menutitle {font-size:14pt; font-weight:bold; margin: 0px; } .content {margin:10px; } .footer { text-align:right; font-size:10pt; margin:10px; border-bottom:solid 1px #ccc; color:#ccc; } </style> </head> <body> <h1>@yield('title')</h1> @section('menubar') <h2 class="menutitle">※メニュー</h2> <ul> <li>@show</li> </ul> <hr size="1"> <div class="content"> @yield('content') </div> <div class="footer"> @yield('footer') </div> </body> </html>
●laravelapp\app\Http\Controllers\Hellocontroller.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Http\Response; class Hellocontroller extends Controller{ public function index(){ return view('layouts.helloapp'); } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。