douba05167 2013-06-06 23:27
浏览 231
已采纳

如何正确显示@yield()内容?

I'm working on learning Laravel and while the quickstart taught me a lot I've been having nothing but problems trying to build off of that.

Currently, I'm trying to use a file public.blade.php as the main public layout for my site. This is working correctly. Within that file, I am trying to display @yield('title') and and @yield('content') within it, this is the part I am having issues with.

Within app/views/public.blade.php I have the following structure:

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>@yield('title')</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
... 
... <!--layout code would be here-->
...
<div class="container">
        <div class="container">
        @yield('content')

        <hr />
        <footer>
            <p>&copy; Example Site 2013</p>
        </footer>
    </div> <!-- /container -->

Within app/views/home.blade.php I have the following:

@extends('public')

@section('title')
    @parent
    BootstrapCMS
@stop

@section('content')
<!-- Main hero unit for a primary marketing message or call to action -->
<div class="hero-unit">
    <h1>Welcome!</h1>
    <p>The goal of BootstrapCMS is to build a basic working content management system built around Twitter Bootstrap. This is primarily for personal learning purposes, as I look to better understand how content management systems function.</p>
    <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
</div>

<!-- Example row of columns -->
<div class="row">
    <div class="span4">
        <h2>&Uuml;ber Secure</h2>
        <p>One of the main goals of this project, aside from basic learning, was to ensure that the design and implementation of all code was safe and secure. For this reason, passwords are securely encrypted using Blowfish, which prevents the password for being decrypted. For this reason, you can be sure that the passwords used with this system, even if leaked online, will be safe and secure.</p>
        <p><a class="btn" href="#">View details &raquo;</a></p>
    </div>
    <div class="span4">
        <h2>Heading</h2>
        <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
        <p><a class="btn" href="#">View details &raquo;</a></p>
   </div>
    <div class="span4">
        <h2>Register Now!</h2>
        <form name="register" action="sections/register/take_register.php" method="POST">
            <div class="control-group">
                <label class="control-label" for="inputUsername">Username</label>
                <div class="controls">
                    <input type="text" class="span4" id="inputUsername" name="registerUsername" placeholder="Username" required>
                </div>
            </div>
          <div class="control-group">
            <label class="control-label" for="inputPassword">Password</label>
            <div class="controls">
              <input type="password" class="span4" id="inputPassword" name="registerPassword" placeholder="Password" required>
            </div>
          </div>
          <div class="control-group">
            <div class="controls">
              <button type="submit" class="btn btn-primary">Register</button>
            </div>
          </div>
        </form>
    </div>
</div>
@stop

I know that I will need to modify the route, so I have my app/routes.php

Route::get('/', function()
{
return View::make('public');
});

I also assume, potentially incorrectly, I need to modify my app/controllers/HomeController.php:

public function showWelcome()
{
    $this->layout->content = View::make('public');
}

I know this has to be more simple than it seems to me right now. What am I missing to get the Laravel @yield('content') to work? Even if you don't want to give me the code, just somewhere where I can learn this or find thorough documentation to help me wrap my head around how this works.

Thank you for your time and assistance.

  • 写回答

1条回答 默认 最新

  • douchi0638 2013-06-06 23:37
    关注

    You are calling the template view (public) and suspect it to be filled with the right content?

    I guess you meant to call View::make('home') which will call call the blade file it extends automatically.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀