Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Syntax Error in python Flask Triangle

Since I wanted to use AngularJS in combination with Flask, I searched for a cool tool to handle these frameworks properly since Jinja and Angular would have problems with each other. I found Triangle which is pretty cool and working but just up to a certain point. Stuff like this works for example:

<a ng-show="post.link" href="{{post.link|angular}}">
    {{post.title|angular}}
</a>

But on the other hand this does not work:

<span>
    <a href="#/posts/{{$index|angular}}">Comments</a>
</span>

When I try to do that, I receive following error

jinja2.exceptions.TemplateSyntaxError

TemplateSyntaxError: unexpected char u'$' at 875

Am I doing something wrong or is the framework just limited in that case? Help is highly appreciated.

like image 376
BoJack Horseman Avatar asked Jan 08 '23 02:01

BoJack Horseman


1 Answers

As the error message is saying, $ cannot be used in Jinja as part of a variable.

Instead, you'll need to change Angular's delimiter notation:

var app = angular.module('Application', []);

app.config(['$interpolateProvider', function($interpolateProvider) {
  $interpolateProvider.startSymbol('{a');
  $interpolateProvider.endSymbol('a}');
}]);

Whatever is chosen for the start and end symbols will act as the new delimiters. In this case, you would express a variable > to Angular using {a some_variable a}.

like image 128
Celeo Avatar answered Jan 22 '23 00:01

Celeo