I'm working on a SF2 application that uses a lot of javascript on the front end.
SF2 provides me a good way of building a nice REST app, manage my database with doctrine, use twig for templates and so on, but I would like to use Angularjs.
I know that angularjs an SF2 are 2 different framework with different approach, but I'm wondering what the best way to make this work is.
Is it even worth it?
If yes, what do you think is the cleaner and most efficient solution?
Maybe use php instead of twig for templates to use angularjs curly braces ?
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. AngularJS's data binding and dependency injection eliminate much of the code you would otherwise have to write.
If you're wondering whether you can use PHP alongside Angular, the answer is yes. But Angular will still need a separate client-server architecture. In general, PHP runs on the server-side while Angular runs on the client-side.
In a hybrid application you run both versions of Angular at the same time. That means that you need at least one module each from both AngularJS and Angular. You will import UpgradeModule inside the NgModule, and then use it for bootstrapping the AngularJS module.
I think Symfony2
can perfectly work well with AngularJS
. Proof is I'm making an API on one side using Symfony, and a web app on the other side with AnglularJS.
Moreover, for some reasons I generate my views in my web app with Twig
. I simply embed angular's curly braces in a twig {% verbatim %} {% endverbatim %}
statement each time I need to use Angular in my views.
As of Twig 1.12 the raw tag was renamed to verbatim:
{% verbatim %} <ul> {% for item in seq %} <li>{{ item }}</li> {% endfor %} </ul> {% endverbatim %}
Everything in-between won't be parsed by the Twig Engine and can be used by AngularJS.
Though I'd recommend changing the AngularJS delimiters. Otherwise it can be hard to distinguish between Twig and AngularJS code when looking at your templates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With