Reputation: 1809
I want to set a default value in javascript in case the {{ }} jinja expression returns nothing. This way the javascript does not throw an error.
Is there some way to make a default value like this in the HTML file:
<script>
var info= {{ python_info | safe }}?self:null;
</script>
If python_info is "" then I want the javascript to be null or some other default value.
I know you can could do an || or solution but this messes up the linting even worse.
Upvotes: 0
Views: 1168
Reputation: 23825
The below should work
<script>
var info = {{ python_info if python_info else 'null' }};
</script>
Upvotes: 1