Laravel 4将刀片语法和html的混合传递给视图

时间:2013-07-11 05:29:13

标签: laravel laravel-4 blade

在我的AnnivesariesController上:

    public function index()
    {
        $annivesaries = Annivesary::where('year', '>', 2011)->take(1)->get();
        $data = "{{{\$annivesary->title }}} annivesary was held in {{{ \$annivesary->year }}}";
        return View::make('annivesaries.index', compact('annivesaries'))
        ->with('user', Auth::user())
        ->with('data', $data);

    }

在我的观点/ annivesaries / index.blade.php:

@foreach ($annivesaries as $annivesary)
         <tr>
            <td>
                {{ link_to_route('annivesaries.show', $data,array($annivesary->id)) }}
            </td>
         </tr>
@endforeach

但是当我访问/ annivessaries路线时,我得到了这个:

{{{$annivesary->title }}} annivesary was held in {{{ $annivesary->year }}}

虽然我真正期待的是:

Annivessary 1 was held in 2011

请让我知道如何达到这一点。

1 个答案:

答案 0 :(得分:1)

您要做的是发送刀片语法以进行查看,但它无法正常工作,因为它已转换为htmlentities

在您的观看{{ link_to_route('annivesaries.show', "$annivesary->title annivesary was held in $annivesary->year",array($annivesary->id)) }}中尝试此操作。