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 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值