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

前端 未结 4 1484
深忆病人
深忆病人 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:27

    My best answer right now would be to state in your view that it must only extend the master template (layout) if the request is not being called via AJAX:

    @if(!Request::ajax())
        @extends('master.template')
    @endif
    

    Note, however, that this solution may not be best for your specific templates (I can only guess that). You'd need to make sure that each template/view only contains things that do not repeat, like side bars, etc. For example, if you have a content area that needs to be updated with pjax, then your view should only contain whatever should be changed.

提交回复
热议问题