Laravel: how to render only one section of a template?

前端 未结 4 1486
深忆病人
深忆病人 2020-12-05 00:50

I\'m trying to use pjax on my site, which means that for a full page request I render the whole template (this is normal behaviour), but on pjax requests I would like to ren

4条回答
  •  甜味超标
    2020-12-05 01:40

    Why wouldn't you just replace the actual content in the rendered page using a div or html element?

    I do this all the time with jQuery. I simply build my initial page and send content to my views that render sections in my master layout.

    Let's say I had a left navigation column and then an article in the right column. The user clicks a button to display the next article, so that's what I want to replace.

    First build the initial view from your controller

    public function index()
    {  
      $article = Article::first();
      Return View::make('homepage', compact('article'));
    }
    

    Now in your homepage view

    @extends('layouts.master')
    
    @section('leftNavigation')
         @include('homepageLeftNavigation')
    @stop
    
    @section('article')
       
    @include('article')
    @stop @section('script') @parent {{--
提交回复
热议问题