2017 © Pedro PelĂĄez
 

library slim-twig-view

Extension for Slim Framework 3 view helper built on top of the Twig 2 templating component

image

adbario/slim-twig-view

Extension for Slim Framework 3 view helper built on top of the Twig 2 templating component

  • Thursday, July 20, 2017
  • by adbario
  • Repository
  • 1 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 7 % Grown

The README.md

Slim Framework Twig View add-on

This is an extension for Slim Framework Twig View with the following extra functions: - adds file extension to template names automatically - uses dot notation for template file paths, (*1)

Installation

composer require adbario/slim-twig-view

Usage

Default extension for the template files is 'twig', this can be changed with the optional setting while registering Twig view on Slim container., (*2)

// Create Slim app
$app = new \Slim\App();

// Fetch DI Container
$container = $app->getContainer();

// Register Twig View helper
$container['view'] = function ($c) {
    $view = new \Adbar\Slim\Views\Twig('path/to/templates', [
        'cache' => 'path/to/cache',
        // Optional template file extension, defaults to 'twig'
        'file_extension' => 'html'
    ]);

    // Instantiate and add Slim specific extension
    $basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
    $view->addExtension(new Slim\Views\TwigExtension($c['router'], $basePath));

    return $view;
};

// Define named route
$app->get('/hello/{name}', function ($request, $response, $args) {
    // Render template file from path 'path/to/templates/user/profile.html'
    return $this->view->render($response, 'user.profile', [
        'name' => $args['name']
    ]);
})->setName('profile');

// Run app
$app->run();

Custom template functions

Read more from Slim Framework Twig View, (*3)

License

MIT license, (*4)

The Versions

20/07 2017

dev-master

9999999-dev https://github.com/adbario/slim-twig-view

Extension for Slim Framework 3 view helper built on top of the Twig 2 templating component

  Sources   Download

MIT

The Requires

 

by Riku SĂ€rkinen

framework twig template slim view

20/07 2017

1.0.0

1.0.0.0 https://github.com/adbario/slim-twig-view

Extension for Slim Framework 3 view helper built on top of the Twig 2 templating component

  Sources   Download

MIT

The Requires

 

by Riku SĂ€rkinen

framework twig template slim view