https://github.com/thecodingmachine/html.renderer
This package contains the rendering mechanism of the Mouf framework. It is a mechanism allowing packages/templates/developers to overload a default template for various HTML objects.
https://github.com/thecodingmachine/html.renderer
Last synced: 8 months ago
JSON representation
This package contains the rendering mechanism of the Mouf framework. It is a mechanism allowing packages/templates/developers to overload a default template for various HTML objects.
- Host: GitHub
- URL: https://github.com/thecodingmachine/html.renderer
- Owner: thecodingmachine
- License: mit
- Created: 2013-07-20T13:40:52.000Z (almost 13 years ago)
- Default Branch: 2.0
- Last Pushed: 2022-12-01T16:36:56.000Z (over 3 years ago)
- Last Synced: 2025-10-09T17:12:08.989Z (8 months ago)
- Language: PHP
- Size: 117 KB
- Stars: 0
- Watchers: 12
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://packagist.org/packages/mouf/html.renderer)
[](https://packagist.org/packages/mouf/html.renderer)
[](https://packagist.org/packages/mouf/html.renderer)
[](https://packagist.org/packages/mouf/html.renderer)
[](https://travis-ci.org/thecodingmachine/html.renderer)
[](https://coveralls.io/github/thecodingmachine/html.renderer?branch=2.0)
[](https://scrutinizer-ci.com/g/thecodingmachine/html.renderer/?branch=2.0)
What is this package?
=====================
This package contains a rendering mechanism to **render objects in HTML**.
For application developers
--------------------------
You are an application developer? [Learn how to use the rendering system](doc/for_application_developers.md) with PHP files or Twig templates
to render your objects or overload renderers provided by packages.
See the video!
For package developers
----------------------
You are a package developer? [Learn how to use the rendering system to allow other users to overload
your renderers easily.](doc/for_package_developers.md)
Installation
------------
```bash
$ composer require mouf/html.renderer ^2
```
The easiest way to use this package is through a dependency injection container compatible with [container-interop/service-providers](https://github.com/container-interop/service-provider).
Once installed, you need to register the [`Mouf\Html\Renderer\RendererServiceProvider`](src/RendererServiceProvider.php) into your container.
If your container supports [thecodingmachine/discovery](https://github.com/thecodingmachine/discovery) integration, you have nothing to do. Otherwise, refer to your framework or container's documentation to learn how to register *service providers*.
### Provided services
This *service provider* provides the following services:
| Service name | Description |
|-----------------------------|--------------------------------------|
| `RendererInterface::class` | The default renderer. An alias to `ChainRenderer::class` |
| `ChainRenderer::class` | A composite renderer asking all other renderers in turn if they can render an object. |
| `customRenderers` | A list of `RendererInterface` objects at the "custom" level (top most level). This list is consumed by the `ChainRenderer` |
| `customRenderer` | A default custom renderer is provided by this package. Out of the box, template files are expected to be in the `src/templates` directory. |
| `packageRenderers` | A list of `RendererInterface` objects at the "package" level (bottom level). This list is consumed by the `ChainRenderer`. When a package you install has a renderer, it will add the renderer to this list (most of the time using the `AbstractPackageRendererServiceProvider` |
| `InitRendererFacadeMiddleware::class` | A PSR-15 middleware that is used to initialize global access to the default renderer. This is needed for the `Renderable` trait to work. |
### Extended services
This *service provider* extends those services:
| Name | Compulsory | Description |
|-----------------------------|------------|----------------------------------------|
| `MiddlewareListServiceProvider::MIDDLEWARES_QUEUE` | *yes* | The `InitRendererFacadeMiddleware::class` registers itself in the list of PSR-15 middlewares. |
Mouf package
------------
This package was originally part of Mouf (http://mouf-php.com), an effort to ensure good developing practices by providing a graphical dependency injection framework.
V2 makes the package framework-agnostic, so it can be used in any framework.
Basically, you will find in this package some **Renderers**. These are classes in charge of rendering other objects.
They usually rely on *template files*, that contain the HTML to be rendered.
Renderers can be *chained*, and the first renderer that knows how to render an object will be in charge of the rendering.
Troubleshooting
---------------
Your template or a custom template is not applied.
* Purge the cache with the red button in mouf.
* You use Ajax and you return html with echo (for example BCE).
* By default an echo don't apply the template to make it
* add the defaultRenderer (a class of Mouf\Html\Renderer\AutoChainRenderer) in your class
* add your templateRenderer (a class of Mouf\Html\Renderer\FileBasedRenderer) in Bootstrap this is bootstrapRenderer
* add the code before your call to the function toHTML: $this->defaultRenderer->setTemplateRenderer($this->templateRenderer);