2

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

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.

Muhammad Raheel
  • 19,823
  • 7
  • 67
  • 103

2 Answers2

4

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>
vFragosop
  • 5,705
  • 1
  • 29
  • 31
2

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

  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

Community
  • 1
  • 1
Marin Sagovac
  • 3,932
  • 5
  • 23
  • 53