Reputation: 3491
I use the mustache interpolation:
_.templateSettings = {
interpolate: /\{\{(.+?)\}\}/g
};
and for this code I get the error: Uncaught SyntaxError: Unexpected token if
<div class="d-none flex-container tip-container bg-white mt-5" data-ajax-template-empty-tip>
<div class="tip-header border border-bottom-0 d-flex flex-row p-2">
<div class="align-self-center mr-2">
<a href="./{{countryName}}" target="_blank">
<img class="d-block" alt="" src="/images/flags/{{countryId}}.png">
</a>
</div>
{{if (typeof(cityName) !== "undefined") { }}
<i class="fas fa-arrow-left align-self-center mr-2"></i>
<div class="align-self-center mr-2">
<a class="badge badge-primary" role="button" href="/city/{{cityName}}" target="_blank">
<span>{{cityName}}</span>
</a>
</div>
{{}}}
</div>
</div>
Without the if statement it works well, but with it won't work, any idea what's wrong? I looked in every question online and couldn't figure it out, I even removed the interpolation and used the default <% but it wouldn't.
Upvotes: 1
Views: 338
Reputation: 1894
Try a space before the if, like this :
{{ if (typeof(cityName) !== "undefined") { }}
Upvotes: -1