user3662399
user3662399

Reputation: 1

Passing a twig variable to an Angular controller

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.

Upvotes: 0

Views: 1350

Answers (1)

Javad
Javad

Reputation: 4397

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

Upvotes: 1

Related Questions