Partials in Laravel

By | 05/12/2019

As a rails developer you have DRY (Don’t Repeat Yourself) drilled into you from the outset – and one of the great tools are partials.

No doubt just scratching the surface with Laravel and navigating my way around partials.
I tend to have a shared directory for cross app reusable code, so created the directory and main_nav.blade.php file.
N.B. There’s no underscore in Laravel to indicate it’s a partial as in Rails.

If your partial inherits from a view add

@extends('view name')

else if you just want to include in a view you just call it from the view.

@include('.directory.file') # using dot notation
@include('.directory/file')

Either way works but note the directory you are in and the relative path to the partial.

I’ll no doubt have to come back to how to pass variables through to partials, so this is surely …tbc