At Cogneato, we are using Symfony’s PHP templating engine to render our views for compatibility with our existing system and for allowing our developers to continue using the same language they’re used to. I was looking for a way to make various services and other “variables” globally available in all view files, like can be done for Twig as mentioned in this cookbook. I asked on Stack Overflow, but didn’t get what I was looking for. We came up with our own solutions. I provided some as my own answer to that question. I will discuss the ones I can think of in this post.
Container
The one answer to my Stackoverflow question pointed out that the $view
object has a container
member object that has services available, and you can also access parameters set in your configuration file. Services would be accessed like (I believe):