zendframework / zend-expressive-platesrenderer

Plates integration for Expressive
BSD 3-Clause "New" or "Revised" License
9 stars 12 forks source link

Proposal to Enable Plates Asset Extension #3

Closed stormwild closed 7 years ago

stormwild commented 8 years ago

Proposal to refactor PlatesRendererFactory to enable asset extension.

use League\Plates\Extension as PlatesExtension;

// Create the engine instance:
$engine = new PlatesEngine();

// Enable asset extension
$engine->loadExtension(new PlatesExtension\Asset($config['paths']['assets']));

This will allow plates-layout.phtml in zend-expressive-skeleton to reference assets similar to:

<img src="<?=$this->asset('zf-logo.png')?>" alt="Zend Expressive" />

Where the assets path is configured in templates.global as:

    'templates' => [
        'extension' => 'phtml',
        'paths' => [
            'assets' => 'public',
            'app'    => ['templates/app'],
            'layout' => ['templates/layout'],
            'error'  => ['templates/error'],
mwillbanks commented 8 years ago

I'm not certain that this is really the place to put it, it's certainly already possible by using a container and the manual instantiation vs. the factory instantiation. The problem you will start to run into is where does that stop for hooking everything?

Basically the factories should be mostly interchangeable and adding implementation logic on each one can lead to highly customized factories that ultimately do several things that are just simply proxying methods.

On one hand, it makes configurability via configuration far quicker but on the other hand, it makes for more of a maintainability nightmare - especially for future versions. I would say customized handling such as this should be done manually. But feel free to disagree :)

stefanotorresi commented 8 years ago

i think the problem is that right now there is no way to configure the PlatesEngine because it's not accessible anywhere, and the renderer factory always instantiate a new one rather than pulling one from the container. so as it stands, the implementation is quite closed, and to customize the engine one would need to replace the whole renderer factory, which is odd.

stormwild commented 8 years ago

I would say customized handling such as this should be done manually.

I understand, I was hoping it would have been good to have it enabled for the skeleton by default.

weierophinney commented 8 years ago

While I get the objections that @mwillbanks raises, the fact is that "asset" helpers are already enabled by default in both the twig and zend-view implementations. As such, we likely should enable them for plates.

I see two ways to do so:

Anybody want to start a pull request? On Dec 12, 2015 10:09 PM, "Alexander R Torrijos" notifications@github.com wrote:

I would say customized handling such as this should be done manually.

I understand, I was hoping it would have been good to have it enabled for the skeleton by default.

— Reply to this email directly or view it on GitHub https://github.com/zendframework/zend-expressive-platesrenderer/issues/3#issuecomment-164220908 .