Coder Social home page Coder Social logo

Comments (3)

froschdesign avatar froschdesign commented on July 19, 2024 1

The skeleton application contains examples for the configurations:
https://github.com/mezzio/mezzio-skeleton/tree/3.12.x/src/MezzioInstaller/Resources/src

from mezzio.

froschdesign avatar froschdesign commented on July 19, 2024 1

@tempfirstuser

@froschdesign I used this $renderer

$renderer = new LaminasViewRenderer();

This creates a separate and isolated renderer and there is no magic, so the configuration of your application is not used here.

But when I've made some investigation of mezzio/mezzio-skeleton package I've found example of using TemplateRendererInterface and passing it from handler factory like this

$container->get(TemplateRendererInterface::class);

And this gives you the prepared renderer of mezzio-laminasviewrenderer:

  • Mezzio\Template\TemplateRendererInterface::class is an alias for Mezzio\LaminasView\LaminasViewRenderer::class
  • Mezzio\LaminasView\LaminasViewRenderer::class is created by the factory Mezzio\LaminasView\LaminasViewRendererFactory::class
  • this factory uses the configuration of your application:
class LaminasViewRendererFactory
{
    public function __invoke(ContainerInterface $container): LaminasViewRenderer
    {
        $config = $container->has('config') ? $container->get('config') : [];
        $config = $config['templates'] ?? [];

        // …
    }
}

https://github.com/mezzio/mezzio-laminasviewrenderer/blob/df463cc65105f54418ce2dfa44be6b9918e7a45b/src/LaminasViewRendererFactory.php#L53-L54

from mezzio.

tempfirstuser avatar tempfirstuser commented on July 19, 2024

@froschdesign I used this $renderer

$renderer = new LaminasViewRenderer();

But when I've made some investigation of mezzio/mezzio-skeleton package I've found example of using TemplateRendererInterface and passing it from handler factory like this

$container->get(TemplateRendererInterface::class);

Then later in handler I was able to use renderer like this

    public function __construct(private TemplateRendererInterface $templateRenderer)
    {}

    public function handle(ServerRequestInterface $request): ResponseInterface
    {
        $content = $this->templateRenderer->render('email::comment-created.phtml', [
            'title' => 'Some title',
        ]);
    }

It works for me!
Also here is my config from ConfigProvider.php

    public function getTemplates(): array
    {
        return [
//            'extension' => 'phtml',
//            'layout'    => 'layout::default',
            'paths'     => [
                 'email' => [
                     __DIR__ . '/../Template/Email'
                 ],
                'layout' => [
                    __DIR__ . '/../Template'
                ]

            ],
        ];
    }

Inside of /Template/Email I have file comment-created and inside of /Template/ I have default.phtml.

Thank you again!

from mezzio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.