Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

default_suffix #641

Open
Auramel opened this issue Oct 6, 2018 · 3 comments
Open

default_suffix #641

Auramel opened this issue Oct 6, 2018 · 3 comments

Comments

@Auramel
Copy link

Auramel commented Oct 6, 2018

Hello! How I can change default_suffix from .phtml on something else?
I use zend-view with service-manager.

@weierophinney
Copy link
Member

There currently isn't a way.

You can make it happen, though. To do so, you will need to create a delegator factory that uses reflection to fetch the NamespacedPathStackResolver attached to the renderer, and then set the suffix on that.

As an example:

use Psr\Container\ContainerInterface;
use ReflectionProperty;
use Zend\Expressive\ZendView\NamespacedPathStackResolver;
use Zend\Expressive\ZendView\ZendViewRenderer;

class TemplatePathSuffixDelegator
{
    public function __invoke(ContainerInterface $container, string $name, callable $callback) : ZendViewRenderer
    {
        $renderer = $callback();
        $r = new ReflectionProperty($renderer, 'resolver');
        $r->setAccessible(true);
        $resolver = $r->getValue($renderer);
        $resolver->setDefaultSuffix('php');
        return $renderer;
    }
}

You would then register this via your dependency configuration:

// In config/autoload/dependencies.global.php:
use Zend\Expressive\ZendView\ZendViewRenderer;

return [
    'dependencies' => [
        'delegators' => [
            ZendViewRenderer::class => [ TemplatePathSuffixDelegator::class ],
        ],
    ],
];

In the meantime, I'm marking this as a feature request, as this is a configuration option we should support.

@Auramel
Copy link
Author

Auramel commented Oct 8, 2018

It working!
Thank you very much!
I believe, that in future will be more easily way

@weierophinney
Copy link
Member

This repository has been closed and moved to mezzio/mezzio; a new issue has been opened at mezzio/mezzio#6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants