davidepastore / slim-markdown-view
Render PHP view scripts into a PSR-7 Response object.
Installs: 1 014
Dependents: 1
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- erusev/parsedown: ^1.6
- psr/http-message: ^1.0
Requires (Dev)
- phpunit/phpunit: ^4.0
- scrutinizer/ocular: ~1.1
- slim/slim: ^3.0
This package is auto-updated.
Last update: 2024-11-26 07:59:38 UTC
README
A renderer for rendering Markdown into a PSR-7 Response object. It works well with Slim Framework 3.
Installation
Install with Composer:
composer require davidepastore/slim-markdown-view
Usage With Slim 3
use \DavidePastore\Slim\Views\MarkdownRenderer; include "vendor/autoload.php"; $app = new Slim\App(); $container = $app->getContainer(); $container['renderer'] = new MarkdownRenderer("./templates"); $app->get('/hello/', function ($request, $response) { return $this->renderer->render($response, "/hello.md"); }); $app->run();
Usage with any PSR-7 Project
//Construct the View $markdownView = new MarkdownRenderer("./path/to/templates"); //Render a file $response = $markdownView->render(new Response(), "/path/to/template.md");
Custom Parsedown instance
//Construct the View $parsedown = Parsedown::instance()->setUrlsLinked(false); $markdownView = new MarkdownRenderer("./path/to/templates", $parsedown); //Render a file $response = $markdownView->render(new Response(), "/path/to/template.md");
Exceptions
\RuntimeException
- if template does not exist
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.