Designinglives

June 23, 2017 at 5:24 pm

Flexible blade setup

Once you have noticed the breeze the blade templating engine will bring into your templates, it’s about time to share a flexible template setup. I’ll share mine below but it’s by far the best setup in every situation.

Our file structure:

Layouts
- master.blade.php

Includes
- header.blade.php
- menu.blade.php

Pages
- page1.blade.php
- page2.blade.php

app/views/layouts/default.blade.php

<!DOCTYPE html>
<html lang="">
<head>
   <meta charset="utf-8">
   <meta name="description" content="@yield('description')">
   <meta name="keywords" content="@yield('keywords')" />

   <title>@yield('title')</title>
</head>
<body>
   @include('includes/header')

   @include('includes/menu')
	
   @yield('content')
	
   @yield('footer')
</body>
</html>

app/views/pages/page1.blade.php

@extends('layouts/master')

@section('title', 'This is an individual page title')
@section('description', 'This is a description')
@section('keywords',	'Keyword 1, Keyword 2, Keyword 3')

@section('content')
   <h1>Titel</h1>
   <p>Content</p>
@stop

@section('footer')
   <script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
@stop

  {{-- Other scripts --}}

app/views/includes/header.blade.php
This file will contain everything related to the header, like logo, contact info, title and subtitle found inside the header, …

app/views/includes/menu.blade.php
As the file says, this contains our menu. I’d like to have this separated because I need to edit this frequently and don’t want the header file to get to complex.

I encourage you to go out, experiment and set this layout structure to your own hand, the best workflow is the one you are the most comfortable with, good luck!

0 likes blade , templates
Share: / / /