ember.js app in sonata-admin

The sonata-project is a great one for creating administrative interfaces with symfony. I like the idea of an admin framework based on symfony and I like ember.js for creating intuitive and compelling administrative interfaces. Thus I liked to combine those two. At first I thougt the easiest is to create an Admin for a stdClass and integrate the ember.js app via a special template. But this leads to a lot of problems with the layout of the sonata-admin. So I changed the my mind and created a separate layout for ember.js apps with a normal symfony controller.

There is one trick to know when creating controllers out of the scope of an Admin, pass the admin pool to the template.

This is easily done by fetching the admin-pool from the container and passing it to the template.

In the template place the {{ output }} in the sonata_admin_content block and don't forget to escape the output as the handlebar syntax is the same as twig's variable output. A second block containing the handlebar templates is just used to separate them from the application stuff.

The ember_layout template contains the same content like the original template but is wrapped by handlebars script tag to identify it as the application template.

That's it now, to link to this action just place a  link in the block "side_bar_after_nav" and you are able to access your ember app directly from the left menu.