8000 GitHub - kadevland/slim-plates-view: Slim Framework 3 view helper built on top of the Plates templating component
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Nov 7, 2019. It is now read-only.

kadevland/slim-plates-view

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slim Framework Plates View

This is a Slim Framework view helper built on top of the Plates templating component. You can use this component to create and render templates in your Slim Framework application.

Install

Via Composer

$ composer require kadevland/slim-plates-view

Requires Slim Framework 3 and PHP 5.5.0 or newer.

Usage

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

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

// Register Plates View helper
$container['view'] = function ($c) {
    $view = new \Kadevland\Slim\Plates\View\PlatesView('path/to/templates','extention');
    
    // Instantiate and add Slim specific extension 
    $basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
    $view->addExtension(new \Kadevland\Slim-Plates-View\PlatesViewExtension($c['router'], $basePath));

    return $view;
};

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

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

Custom template functions

This component exposes a custom path_for() function to your Plates templates. You can use this function to generate complete URLs to any Slim application named route. This is an example Plates template:

<h1>User List</h1>
<ul>
    <li><a href="<?= $this->path_for('profile', { 'name': 'josh' }) ?>">Josh</a></li>
</ul>

This component propose a feature is_url() function to your Plates templates. You can use this function to check if URL match witch Request URL/Path. This is an example Plates template:

<h1>Categories List</h1>
<ul>
---
$link=path_for('categorie', { 'slug': 'my-categorie' });
    <li class="<?=$this->is_url($link)?'active':''?>"><a href="<?=$link?>">My categorie</a></li>
---
</ul>

Testing

phpunit

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0