Send variable to the layout in laravel4 with Blade

Asked

Viewed 575 times

-1

I have a problem here I need to send a variable to my layout, I tried so:

On the controller

$this->layout->page = 'Atendentes';

and in the layout that

@yield('page')

the problem is that I need to compare this page variable within an if that in case is:

@if ( @yield('page') == 'Atendentes' )
    //do something
@endif

but it embarrasses the php tags, it returns me an error with the code like this:

<?php if ( <?php echo $__env->yieldContent('page') == 'Atendentes' ); ?>: ?>
  • Try @if ($page == 'Atendentes' ).

  • he does not find the variable

  • Errorexception Undefined variable: page

  • Ah, you are passing the variable through the layout. Try passing this variable in the View::make call of your method as array in the second argument: View::make('path.do.view', [ 'page' => 'Atendentes'])

  • so I’m passing the variable to my layout, if I go through the view it goes only to the view is not accessible in the layout

1 answer

2

I did it using view::share in controller to share a variable in all my views

   $page = 'Atendentes';
   View::share('page', $page);
  • 1

    $this->layout->with('page' => 'Atendentes'); another way to get the same result

Browser other questions tagged

You are not signed in. Login or sign up in order to post.