Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

default_suffix #6

Closed
weierophinney opened this issue Dec 31, 2019 · 3 comments
Closed

default_suffix #6

weierophinney opened this issue Dec 31, 2019 · 3 comments
Labels
Enhancement New feature or request Help Wanted

Comments

@weierophinney
Copy link
Contributor

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


Originally posted by @Auramel at zendframework/zend-expressive#641

@weierophinney weierophinney added Enhancement New feature or request Help Wanted labels Dec 31, 2019
@weierophinney
Copy link
Contributor Author

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.


Originally posted by @weierophinney at zendframework/zend-expressive#641 (comment)

@weierophinney
Copy link
Contributor Author

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


Originally posted by @Auramel at zendframework/zend-expressive#641 (comment)

@arueckauer
Copy link

Is this feature completed with zendframework/zend-expressive-zendviewrenderer#64 and zendframework/zend-expressive-zendviewrenderer#67?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request Help Wanted
Projects
None yet
Development

No branches or pull requests

3 participants