figdice/slim-view

Slim Framework 3 view helper built on top of the FigDice templating component

dev-master 2015-12-03 10:23 UTC

This package is not auto-updated.

Last update: 2024-12-21 19:33:11 UTC


README

Slim Framework 3 Delegate for FigDice View

Container (DI) View component for the Slim Framework 3, that wires FigDice Templating library into Slim.

Read Slim Views Documentation for more details.

Installation

In composer.json:

"require": {
  "figdice/slim-view": "*"
}

Usage

1. Register FigDice SlimView component in Slim container

// Create container
$container = new \Slim\Container;

// Register component on container
$container['view'] = function ($c) {
  $slimview = new \figdice\slim\SlimView('path/to/templates');
  
  // Optionally configure FigDice View settings
  // (cache directory, dictionaries, feed & function factories, etc.)
  $slimview->getView()->setTempPath('path/to/cache');
  $slimview->getView()->registerFeedFactory( new MyFeedFactory(...) );
  // ...
  
  return $slimview;
};

2. Render FigDice templates in Slim routes

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

// Render FigDice template in route
$app->get('/hello/{name}', function ($request, $response, $args) {
    return $this->view->render($response, 'profile.html', [
        'name' => $args['name']
    ]);
});

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