【问题标题】:Laravel Templating nest viewsLaravel 模板化嵌套视图
【发布时间】:2012-12-16 20:59:30
【问题描述】:

我不知道如何在没有 Blade 的情况下将几个视图合并到一个部分中。

控制器:

public $layout = 'layouts.template';
action_index{
    $this->layout->nest('content', 'view1');
    $this->layout->nest('content', 'view2');
}

模板.php:

<?php echo Section::yield('content'); ?>

view1.php:

<?php Section::start('content');?>
div1....
<?php Section::stop(); ?>

view2.php:

    <?php Section::start('content');?>
div2....
<?php Section::stop(); ?>

现在 - 它只显示 view2

如何实现这样的目标:

$content = View::make('view1');
$content = View::append('view2'); // append view2 to view1?
$this->layout->with('content', $content);

【问题讨论】:

  • 我知道您没有使用 Blade,但请考虑使用它。在那里筑巢很容易。

标签: php templates laravel


【解决方案1】:
$content = View::make( 'view1' ) . View::make( 'view2' );

这应该可行。 View 类中有一个 __toString 魔术方法,因此当它遇到字符串连接运算符时,它会呈现为字符串。 $content 将是一个字符串,其中包含来自两个渲染视图的 HTML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-07
    • 2015-10-13
    • 2011-10-30
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 2017-04-10
    相关资源
    最近更新 更多