2017 © Pedro Peláez
 

library slim

Pug template engine adapter for Slim

image

pug/slim

Pug template engine adapter for Slim

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 38 % Grown

The README.md

Pug for Slim

Latest Stable Version Build Status Code Climate Test Coverage Issue Count StyleCI, (*1)

For details about the template engine see phug-lang.com, (*2)

Installation

Install with Composer:, (*3)

composer require pug/slim

Usage with Slim 3

use Slim\App;
use Slim\Pug\PugRenderer;

include 'vendor/autoload.php';

$slimOptions = []; // here you can pass Slim settings
$app = PugRenderer::create(new App($slimOptions), './templates');

$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->renderer->render($response, 'hello.pug', $args);
});

$app->run();

PS: If you don't pass an application to the create method, we will automatically initialize one, so you can just do:, (*4)

use Slim\Pug\PugRenderer;

include 'vendor/autoload.php';

$app = PugRenderer::create(null, './templates');

Usage with any PSR-7 Project

//Construct the View
$pugView = new PugRenderer('./path/to/templates', [
  'option' => 'foobar',
]);

//Render a Template
$response = $pugView->render(new Response(), '/path/to/template.pug', $yourData);

Template Variables

You can add variables to your renderer that will be available to all templates you render., (*5)

// via the constructor
$templateVariables = [
  'title' => 'Title',
];
$pugView = new PugRenderer('./path/to/templates', [], $templateVariables);

// or setter
$pugView->setAttributes($templateVariables);

// or individually
$pugView->addAttribute($key, $value);

Data passed in via ->render() takes precedence over attributes., (*6)

$templateVariables = [
  'title' => 'Title',
];
$pugView = new PhpRenderer('./path/to/templates', $templateVariables);

//...

$pugView->render($response, $template, [
    'title' => 'My Title',
]);
// In the view above, the $title will be "My Title" and not "Title"

By default, pug-php is used. But you can specify an other engine:, (*7)

$app = PugRenderer::create(null, null, [
  'renderer' => \Phug\Renderer::class,
]);

PS: Phug is automatically installed with default install since Pug-php 3 use it internally. But you can also install different renderer engine, for example tale-pug:, (*8)

composer require talesoft/tale-pug
$app = PugRenderer::create(null, null, [
  'renderer' => \Tale\Pug\Renderer::class,
]);

Note that in this case, you have no guarantee that all options will work., (*9)

References

Credits

This project is forked from https://github.com/MarcelloDuarte/pug-slim And we added to it phug, pug-php 3, tale-jade and tale-pug support., (*10)

The Versions

12/12 2017

dev-master

9999999-dev

Pug template engine adapter for Slim

  Sources   Download

MIT

The Requires

 

The Development Requires

php html slim jade pug phug

12/12 2017

1.1.0

1.1.0.0

Pug template engine adapter for Slim

  Sources   Download

MIT

The Requires

 

The Development Requires

php html slim jade pug phug

25/06 2017