0
votes

I'm using Laravel and passing some variables to views to echo them out using the blade syntax like so:

@extends('masterLayout')

@section('content')
    @foreach($products $product)
        <p>{{ $product->name}}</p>
    @endforeach @stop
@end

In the masterLayout.blade.php file is the layout for the page, with the <html><head> and <body> tags. Problem is, when these variables are being passed to the view and echo'd they're not being put within the page where they should be. All the echo'd out data is placed at the top of the page above the HTML tag as if I were echoing it out in the controller and not in the view. Is there a setting to change within Laravel or a different way to achieve this?

EDIT: Okay here's the entire code of the views. there's actually three, inventory, inventoryLayout, and masterLayout. I've commented out the return View::make() in the controller and it disappears so I'm definitely not echoing it anywhere other than in the view itself. The help is appreciated!

master.blade.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>AppName</title>

    <link rel="stylesheet" href="../assets/css/frontend.css">
</head>
<body>
<header class="navbar navbar-inverse navbar-fixed-top bs-docs-nav" role="banner">

  <nav id='top-nav'>
    <div class="centered-wrapper">
        <ul>
            <li><?php echo link_to('/login',"Login");?></li>
            <li><?php echo link_to('/admin',"Admin");?></li>
            <li><?php echo link_to('/inventory',"Inventory");?></li>
            <li><?php echo link_to('/dashboard',"Dashboard");?></li>
            <li><?php echo link_to('/recipes',"Recipes");?></li>
            <li><?php echo link_to('/shopping_list',"Shopping List");?></li>
        </ul>
    </div>
</nav>
</header>
    <div id="container">
        @yield('content')
    </div><!-- end container -->
</body>
</html>

inventoryLayout.blade.php

@extends('layouts.master')

<h1>My Inventory</h1>

@yield('inventoryItems')

inventory.blade.php

@extends('inventoryLayout')

@section('inventoryItems')
    @foreach($products as $product)
        <p>{{{ $product->name }}}</p>
    @endforeach
@stop
2
It might be worth you posting the contents of masterLayout just so we can see. I notice though that the code you have above has a sneaky @stop after the foreach and an @end (which I don't think does anything in Blade).alexrussell

2 Answers

0
votes
  1. @foreach($products $product) should be @foreach($products as $product)
  2. Try commenting out the line where you return a View in your controller. If the page does not turn white, you know you're echoing something from within the controller.
  3. Try to search for varchar, print_r, echo or dd in your controller.
  4. What's in your master layout?
0
votes

Figured it out myself. I was including a section called 'content' but never actually created that section in a child view, so instead of placing that section in the page it was just putting it above the page. this fixed it

inventoryLayout.blade.php

@extends('layouts.master')

@section('content');
<h1>My Inventory</h1>

@yield('inventoryItems')
@stop