使用没有刀片的 Laravel 模板显示内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15253821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:36:26  来源:igfitidea点击:

Displaying Content with laravel template without blade

phplayoutlaravellaravel-4

提问by Muhammad Raheel

I have this controller method

我有这个控制器方法

class Account_Controller extends Base_Controller
{
    public $layout = 'layouts.default';

    public function action_index($a,$b)
    {
        $data['a']  =   $a;
        $data['b']  =   $b;

        $this->layout->nest('content', 'test',$data);
    }
}

And this is my layout

这是我的布局

<div id = "content">
    <?php echo Section::yield('content'); ?>
</div>

And this is my test.php

这是我的 test.php

echo $a;
echo '<br>';
echo $b;
echo 'this is content';

When i access this

当我访问这个

http://localhost/myproject/public/account/index/name/email

I get my layout loaded but test.php is not loaded. How can i load content in my template. I dont want to use blade.

我加载了我的布局,但未加载 test.php。如何在我的模板中加载内容。我不想用刀片。

回答by vFragosop

When you nest a view within another it's content is defined as a simple variable. So, simply output it:

当您将一个视图嵌套在另一个视图中时,它的内容被定义为一个简单的变量。所以,简单地输出它:

<?php echo $content ?>

Section is used when you need to change something on your layout (or any parent view really) from within the child view. For instance:

当您需要从子视图中更改布局(或任何父视图)上的某些内容时,将使用部分。例如:

// on layout.php
<title><?php echo Section::yield('title') ?></title>
// on test.php
<?php Section::start('title'); ?>
    My Incredible Test Page
<?php Section::stop(); ?>

<div class="test_page">
    ...
</div>

回答by Marin Sagovac

I think you need render for it, not sure, maybe partial loading:

我认为你需要渲染它,不确定,也许是部分加载:

<div class="content">
    <?php echo render('content.test'); ?>
</div>

Look this sample for nesting views: http://laravel.com/docs/views#nesting-views

查看此示例以获取嵌套视图:http: //laravel.com/docs/views#nesting-views

  public function action_dostuff()
   {
      $view = View::make('controller.account');
      // try dump var to grab view var_dump($view);
      var_dump($view);
      $view->test = 'some value';
      return $view;
   }

Or use instead blade: Templating in Laravel

或者使用刀片:Laravel 中的模板