0

我是 laravel 的新手,我遇到了一个问题。

public function index($type = null)
{
    $items = $this->best();
    if (Request::ajax())
        return View::make('item_main', $items) -> with('items',$items);
    else
        $this->layout->content = View::make('main', $items) -> with('items',$items);
}

我的 main.blade.php 看起来像这样:

@extends('layouts.master')

@section('sidebar')
    @parent

    <p>This is appended to the master sidebar.</p>
@stop

@section('content')
    @foreach ($items as $item)
        {{$item->myth}}
    @endforeach 
@stop

对于ajax,我只需要加载

@foreach ($items as $item)
    {{$item->myth}}
@endforeach 

我如何在不重复这部分代码的情况下做到这一点?

我坚持要在刀片内部加载视图。那就是我在codeigniter中所做的。

非常感谢!

4

1 回答 1

0
public function index($type = null)
    {
        $items = $this->best();
        if (Request::ajax())
            return View::make('item_main') -> with('items',$items);
        else
            $this->layout->content = View::make('main') -> with('items',$items);
    }

item_main.blade.php:

@foreach ($items as $item)
    {{$item->myth}}
@endforeach 

main.blade.php:

@extends('layouts.master')

@section('sidebar')
    @parent

    <p>This is appended to the master sidebar.</p>
@stop

@section('content')
    @include('item_main')
@stop

归功于 Wrikken。

于 2013-07-12T00:46:44.243 回答