2017 © Pedro Peláez
 

composer-plugin laravel-pug

Pug view adapter for Laravel

image

bkwld/laravel-pug

Pug view adapter for Laravel

  • Thursday, March 22, 2018
  • by weotch
  • Repository
  • 5 Watchers
  • 75 Stars
  • 15,011 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 9 Forks
  • 0 Open issues
  • 23 Versions
  • 11 % Grown

The README.md

Laravel Pug

Packagist GitHub Actions StyleCI codecov Code Climate License, (*1)

A small package that adds support for compiling Pug (Jade) templates to Laravel via Pug.php (see complete documentation). Both vanilla php and Blade syntax is supported within the view., (*2)

This is the documentation for the ongoing version 2.0. Click here to load the documentation for 1.11, (*3)

Installation

First you need composer if you haven't yet: https://getcomposer.org/download/, (*4)

Now open a terminal at the root of your Laravel project. If it's a new project, create it with: composer create-project --prefer-dist laravel/laravel my-new-project (replace my-new-project with your own project name, see the documentation for further information), (*5)

Then run:, (*6)

composer require bkwld/laravel-pug

Usage

Route::get('/', function () {
    return view('my-page');
});

Will now try to load views/my-page.pug first, or views/my-page.blade.pug or fallback to the default blade engine loading views/my-page.blade.php., (*7)

As with Blade, you can pass variables to your view:, (*8)

Route::get('/', function () {
    return view('my-page', [
        'user' => Auth::user(),
        'messages' => ['Hello', 'Bye'],
    ]);
});

Any file with the extension .pug will be compiled as a pug template. Laravel Pug also registers the .pug.blade which also compile blade code once Pug code has been compiled; but we highly recommend you to use the clean and standard extension .pug that will be recognized by most systems. It compiles your Pug templates in the same way as Blade templates; the compiled template is put in your storage directory. Thus, you don't suffer compile times on every page load., (*9)

In other words, just put your Pug files in the regular views directory and name them like whatever.pug. You reference them in Laravel like normal such as view('home.whatever') for resources/views/home/whatever.pug., (*10)

The Pug view files can work side-by-side with regular PHP views., (*11)

Use Blade in Pug templates

This feature is designed for transition purpose, since every blade features are available in pug, you would not need both., (*12)

To use Blade templating within your Pug, just name the files with .blade.pug extensions., (*13)

Read more
, (*14)

Be aware that this mode will first render your template with pug, then give the output to render to blade, it means your template must have a valid pug syntax and must render a valid blade template. This also means blade directives are only available through pug text output, see the example below:, (*15)

| @if ($one === 1)
div $one = 1
| @endif
p {{ $two }}

If you render this with the following values: ['one' => 1, 'two' => 2], you will get:, (*16)

<div>$one = 1</div>
<p>2</p>

PS: note that you would get the same output with the following pure pug code:, (*17)

if one === 1
  div $one = 1
p=two

, (*18)

Use in Lumen

Register the service in bootstrap/app.php (Register Service Providers section is the dedicated place):, (*19)

$app->register(Bkwld\LaravelPug\ServiceProvider::class);

Then you can use it with view():, (*20)

$router->get('/', function () use ($router) {
    // will render resources/views/test.pug
    return view('test', [
        'name' => 'Bob',
    ]);
});

Configuration

All Pug.php options are passed through via a Laravel config array file you can edit /config/laravel-pug.php, (*21)

If for any reason, the config file is missing, just run the following command: php artisan vendor:publish --provider="Bkwld\LaravelPug\ServiceProvider", (*22)

Extending Layouts / Include Sub-views

Default root directory for templates is resources/views, so from any template any deep in the directory, you can use absolute paths to get other pug files from the root: extends /layouts/main will extends the file resources/views/layouts/main.pug, include /partial/foo/bar, will include resources/views/partial/foo/bar.pug. You can use the basedir option to set the root to an other directory. Paths that does not start with a slash will be resolved relatively to the current template file., (*23)

History

Read the Github project releases for release notes., (*24)

The Versions

06/12 2017

dev-cache-imports-handle

dev-cache-imports-handle

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robert Reinhard

01/11 2017

dev-warn-breaking-changes

dev-warn-breaking-changes

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robert Reinhard

07/10 2017

dev-pug-php-3-compatibility

dev-pug-php-3-compatibility

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Robert Reinhard

29/08 2017

dev-analysis-zDY1a5

dev-analysis-zDY1a5

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard

23/08 2017

1.3.1

1.3.1.0

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard

23/08 2017

dev-auto-publish-vendor

dev-auto-publish-vendor

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard

11/05 2017

1.3.0

1.3.0.0

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard

27/03 2017

1.2.0

1.2.0.0

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard

29/07 2016

1.1.0

1.1.0.0

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard

20/07 2016

1.0.0

1.0.0.0

Pug view adapter for Laravel

  Sources   Download

MIT

The Requires

 

by Robert Reinhard