What are the Slack Archives?

It’s a history of our time together in the Slack Community! There’s a ton of knowledge in here, so feel free to search through the archives for a possible answer to your question.

Because this space is not active, you won’t be able to create a new post or comment here. If you have a question or want to start a discussion about something, head over to our categories and pick one to post in! You can always refer back to a post from Slack Archives if needed; just copy the link to use it as a reference..

We want to render PDF files. And we use twig for that because it is HTML to PDF. Our problem now is

UM4BZSK7T
UM4BZSK7T Posts: 174 πŸ§‘πŸ»β€πŸš€ - Cadet

We want to render PDF files. And we use twig for that because it is HTML to PDF. Our problem now is how to get a fully configured Twig Service? If we setup twig ourself we would have to inject loads of different things. We found a twig trait but those functions only use an existing twig. The Controller has an already setup twig but I don't think it is wise to inject that somewhere else. So how do I get a fully setup twig from the global scope?

Comments

  • UM4BZSK7T
    UM4BZSK7T Posts: 174 πŸ§‘πŸ»β€πŸš€ - Cadet

    We are using the \Spryker\Yves\Twig\TwigFactory still that is missing the trans function

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    you can access the global (app) container from the controller I think?

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    so maybe you could register your service in the app container and use it in the controller? (i.e. implement it "outside" of Spryker)

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    not sure if it's currently possible to provide global dependencies in the dependency providers

  • UM4BZSK7T
    UM4BZSK7T Posts: 174 πŸ§‘πŸ»β€πŸš€ - Cadet

    We have twig configured for controllers. That is done during the bootstrap. But as we use a DTO for the data to get that in our PDF service we loose the reference. So now we do the translation inside of the controller and pass those translated strings to the DTO.

  • UM4BZSK7T
    UM4BZSK7T Posts: 174 πŸ§‘πŸ»β€πŸš€ - Cadet

    Maybe I am missing something but from my Symfony perspective I would just inject the service and all would be fine. That seems not to be possible in Spryker.

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    no, it's not AFAIK

  • UM4BZSK7T
    UM4BZSK7T Posts: 174 πŸ§‘πŸ»β€πŸš€ - Cadet

    Ricardo did know what to do! ❀ So you have to build inside of your DI a new Pimple instance and that can give you a new globally configured twig for you. Probably wasts loads of resources :D

  • ULYHEM6M7
    ULYHEM6M7 Posts: 13 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2019

    Yes you can load the Application from the Pimple (inside the Factory of cause) and from there you can get the current Twig Env

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2019

    so rebuild the container from scratch? or?

  • UM4BZSK7T
    UM4BZSK7T Posts: 174 πŸ§‘πŸ»β€πŸš€ - Cadet
    edited December 2019

    Yes with a nice and shiny new Pimpel() 🧑

  • UKGT7RC7P
    UKGT7RC7P Posts: 538 πŸ§‘πŸ»β€πŸš€ - Cadet

    ⭐