Laravel刀片模板无法正常工作

时间:2014-09-20 17:49:06

标签: laravel blade

我之前已经开发了Laravel项目,但不知怎的,我无法解决Blade问题。我的@section和@include都因某些原因无效。这是我的文件:

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"
}

视图/布局/ 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>

视图/分/ header.blade.php

some menu based html goes here

视图/分/ footer.blade.php

some plain html content goes here

应用程序/ routes.php文件

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

应用程序/控制器/ StaticController.php

public function index(){

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

应用程序/视图/静态/ 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

应用程序/视图/分/ 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>

现在我在服务器上运行这样的url:http://localhost/laraecom我得到一个空白页面。当我检查源html时,我得到类似的东西

<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">

这意味着我的@section@include都无效

2 个答案:

答案 0 :(得分:0)

app / views / static / index.blade.php 中,您在文件末尾有两个 @stop ,删除一个就可以了。

答案 1 :(得分:0)

我不是专家,因为我写了这个,但我已经多次查看了你的代码

看看被引用的内容我可以看到它确实包含了所有文件并按要求生成内容但是从我能看到它的部分导致问题就在这里

<?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
            }
        }
        ?>

按照您的代码,我可以看到它正在提取所有文件及其内容,这是正确的,但它正好在此PHP代码之前根据您从浏览器输出提供的示例进行剪切。

我不知道它在哪里获取这些信息但是尝试删除这个放入一些纯文本只是为了看它是否写出然后你可以看到模板是否有效并且从那里你可以判断它是否是PHP语句造成这个问题。

我无法判断if语句的用途或信息来自何处,因此我无法定义其输出应该是什么......

您也可以尝试PHP转储$ mainBanners以查看该变量中是否有任何内容。?

或者,如果需要进一步的帮助,您可以粘贴以及传递此信息的位置示例,并从浏览器中分享更完整的输出?