0

I'm using Angular and Twig. Is there a way I can call an Angular function called initItems in my html like inside a

{% for post in posts%} //twig
    <% verbatim %>
       {{initItems(post)}}  //angular
    <% endverbatim %>
{% endfor %}

when post is a twig variable? Inside my initItems function in my controller, post is showing up as undefined.

1 Answers1

1

What you need to do is first changing the start and end interpolation for AngularJS to something else like

angular.module('myApp', []).config(function($interpolateProvider){
    $interpolateProvider.startSymbol('{[{').endSymbol('}]}');
});

Now you can do combine it with your twig

{% for post in posts %} //twig
   <% verbatim %>
     {[{initItems( {{ post }} )}]}  //angular start with {[{ and end with }]}
   <% endverbatim %>
{% endfor %}

You can also check this link for more info

Javad
  • 4,339
  • 3
  • 21
  • 36