Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/prinsfrank/indentingpersistentbladecompiler

Extension on the Laravel Blade compiler that persists indenting when using replaced content in blade templates.
https://github.com/prinsfrank/indentingpersistentbladecompiler

blade blade-compiler blade-template-engine compiler laravel laravel-framework laravel-package template-compiler

Last synced: 2 months ago
JSON representation

Extension on the Laravel Blade compiler that persists indenting when using replaced content in blade templates.

Awesome Lists containing this project

README

        

# Indenting persistent blade compiler

[![Build Status](https://travis-ci.org/PrinsFrank/IndentingPersistentBladeCompiler.svg?branch=master)](https://travis-ci.org/PrinsFrank/IndentingPersistentBladeCompiler)

Have you ever looked at the HTML Laravel generates and wondered about the mess? That's what I want to solve with this package. [As this is not going to be fixed in Laravel Framework itself](https://github.com/laravel/framework/pull/28768) I decided to make it into a package, and here it is!

## The problem
An example with all replaced content types:
```
// app.blade.php
@push('scripts')

@endpush


@stack('scripts')



@section('sidebar')

@show


@yield('content')

```
```
// main.blade.php
@extends('example.app')

@section('sidebar')
@parent

@endsection

@section('content')

@include('example.include')
@includeif('example.include')
@includewhen(true, 'example.include')
@includefirst(['example.include', 'example.include'])


@each('example.include', [1,2], 'index')


@component('example.component')
@slot('title')


@endslot


@endcomponent

@endsection
```
```
// component.blade.php


{{ $title }}

{{ $slot }}

```
```
// include.blade.php

```
Results in the following HTML. What a mess, right?
```
























```
This package fixes that and generates the following HTML:
```






































```

## Setting things up

Run ```composer require prinsfrank/indenting-persistent-blade-compiler```

Run ```php artisan view:clear``` to clear the already compiled views. Don't forget to do this when deploying to production as well, existing templates will break!