Ashutosh
Ashutosh

Reputation: 4675

Laravel blade template not working

I have developed Laravel projects earlier but somehow I'm not able to solve the Blade issue. My @section and @include both are not working for some reason. Here are my files:

composer.json

{
"name": "educo/laraecom",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"require": {
    "laravel/framework": "4.1.*",
    "laravelbook/ardent" : "2.*"
},
"autoload": {
    "classmap": [
        "app/commands",
        "app/controllers",
        "app/models",
        "app/database/migrations",
        "app/database/seeds",
        "app/tests/TestCase.php"
    ]
},
"scripts": {
    "post-install-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-update-cmd": [
        "php artisan clear-compiled",
        "php artisan optimize"
    ],
    "post-create-project-cmd": [
        "php artisan key:generate"
    ]
},
"config": {
    "preferred-install": "dist"
},
"minimum-stability": "stable"
}

views/layouts/index.blade.php

<!DOCTYPE html>
<html>
<head>
<title>Sports Gears</title>

{{HTML::style(asset("/public/css/common"))}}
{{HTML::style(asset("/public/css/jRating.jquery"))}}
{{HTML::style(asset("/public/css/cart"))}}
{{HTML::style(asset("/public/css/bootstrap.min"))}}
{{HTML::style(asset("/public/css/font-awesome"))}}
{{HTML::style(asset("/public/css/jquery.raty"))}}
{{HTML::style(asset("/public/css/homestyle.css"))}}

{{HTML::script(asset('/public/js/jquery'))}}
{{HTML::script(asset('/public/js/jquery-ui.min'))}}
{{HTML::script(asset('/public/js/jquery.ui.autocomplete.min'))}}
{{HTML::script(asset('/public/js/jquery.raty'))}}
{{HTML::script(asset('/public/js/common'))}}
{{HTML::script(asset('/public/js/cart'))}}

</head>
<body>

<div class="header">
   @include('sub.header')
</div>

<div class="container">
    @yield('content')
</div>

<div class="footercontainer">
    @include('sub.footer')
</div>

</body>
</html>

views/sub/header.blade.php

some menu based html goes here

views/sub/footer.blade.php

some plain html content goes here

app/routes.php

Route::get('/', "StaticController@index");

app/controllers/StaticController.php

public function index(){

    return View::make('static.index');    
}

app/views/static/index.blade.php

@extends('layouts.index')

@section('content')

{{HTML::style(asset("/public/css/jquery-ui.css", "stylesheet"))}}
{{HTML::style(asset("/public/css/jquery.autocomplete.css", "stylesheet"))}}

{{HTML::script(asset('/public/js/bootstrap.min'))}}
{{HTML::script(asset('/public/js/jquery.flexslider-min.js'))}}

<div class="clear"></div>
<div class="row">
<div class="content-box">
    <div class="col-lg-12" style="height:370px">
        <div class="col-lg-9 col-xs-12">
            @include('sub.slider')
        </div>
    </div>
    <div class="offerbar col-lg-12">

        <div class="deal-heading col-lg-12">
            <div class="col-lg-4">
                <div class="divider" style="float: right;"></div>
            </div>
            <div class="col-lg-4">
                <p>GET BEST DEAL</p>
            </div>
            <div class="col-lg-4">
                <div class="divider" style="float: left;"></div>
            </div>
        </div>
    </div>
</div>

@stop

app/views/sub/slider.blade.php

<div class="slider">

<div class="flexslider">
    <ul class="slides">
        <?php
        if (!$mainBanners->isEmpty()) {

            foreach ($mainBanners as $banner) {

                $filename = $banner->savedfilename;
                $url = $banner->url;
        ?>
                <li><a href="{{$url}}">{{HTML::image(asset("/public/banners/" . $filename))}}</a></li>
        <?php
            }
        }
        ?>
    </ul>
</div>
</div>

Now when I run the url on server like this: http://localhost/laraecom I get a blank page. When I check the source html, I get something like this

<link media="all" type="text/css" rel="stylesheet" href="https://localhost/laraecom/public/css/jquery-ui.css">
<link media="all" type="text/css" rel="stylesheet" href="https://localhost/laraecom/public/css/jquery.autocomplete.css">

<script src="http://localhost/laraecom/public/js/bootstrap.min"></script>
<script src="http://localhost/laraecom/public/js/jquery.flexslider-min.js"></script>

<div class="clear"></div>
<div class="row">
<div class="content-box">
    <div class="col-lg-12" style="height:370px">
        <div class="col-lg-9 col-xs-12">
            <div class="slider">

<div class="flexslider">
    <ul class="slides">

This means both my @section and @include are not working

Upvotes: 0

Views: 3711

Answers (2)

XenitXTD
XenitXTD

Reputation: 69

I am no expert as I write this but i have looked through your code several times

Looking at what is being referenced i can see that it does indeed include all your files and yield the content as requested however the part where from what i can see it causes problem is here

<?php
        if (!$mainBanners->isEmpty()) {

            foreach ($mainBanners as $banner) {

                $filename = $banner->savedfilename;
                $url = $banner->url;
        ?>
                <li><a href="{{$url}}">{{HTML::image(asset("/public/banners/" . $filename))}}</a></li>
        <?php
            }
        }
        ?>

Following your code i can see that it is pulling in all the files and their content which is correct but it is just before this PHP code that it cuts of according to the Sample you provided from the browser output.

I dont know where it is getting this information but try removing this putting in some plain text just to see if it writes out and then you can see if the templates work and from there you can tell if its the PHP Statement that is causing the issue.

I cant tell what the if statement is for or where its information is coming from so I cannot define what its output should be...

You can also try to PHP dump the $mainBanners to see if there is anything in that variable.?

Or for further assistance you can paste and example of where you are passing this information from as well has share a more complete output from your browser?

Upvotes: 1

marcanuy
marcanuy

Reputation: 23942

In app/views/static/index.blade.php you have two @stop at the end of the file, remove one and it will work.

Upvotes: 0

Related Questions