Skip to content

Commit

Permalink
fix README
Browse files Browse the repository at this point in the history
  • Loading branch information
l0gicgate committed Apr 28, 2019
1 parent 4de64d0 commit 80cc982
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use Slim\Views\Twig;
use Slim\Views\TwigExtension;
use Slim\Views\TwigMiddleware;

require __DIR__ . '/vendor/autoload.php';

// Create Container
$container = new Container();
AppFactory::setContainer($container);
Expand All @@ -31,10 +33,10 @@ AppFactory::setContainer($container);
$app = new AppFactory::create();

// Add Twig-View Middleware
$baseUrl = 'http://www.yourwebsite.com';
$basePath = '/base-path';
$routeParser = $app->getRouteCollector()->getRouteParser();
$twig = new Twig('path/to/templates', ['cache' => 'path/to/cache']);
$twigMiddleware = new TwigMiddleware($twig, $container, $routeParser, $baseUrl);
$twigMiddleware = new TwigMiddleware($twig, $container, $routeParser, $basePath);
$app->add($twigMiddleware);

// Define named route
Expand All @@ -61,12 +63,11 @@ $app->run();

`TwigExtension` provides these functions to your Twig templates:

* `base_url()` - returns the base URL from the incoming Request object
* `current_url()` - returns the current path, with or without the query string.
* `is_current_url()` - returns true is the provided route name and parameters are valid for the current path.
* `url_for()` - returns the URL for a given route. e.g.: /hello/world
* `full_url_for()` - returns the URL for a given route. e.g.: http://www.example.com/hello/world

* `is_current_url()` - returns true is the provided route name and parameters are valid for the current path.
* `current_url()` - returns the current path, with or without the query string.
* `get_uri()` - returns the `UriInterface` object from the incoming `ServerRequestInterface` object

You can use `url_for` to generate complete URLs to any Slim application named route and use `is_current_url` to determine if you need to mark a link as active as shown in this example Twig template:

Expand Down

0 comments on commit 80cc982

Please sign in to comment.