2

looking at the google web eng example;

{% for greeting in greetings %}
  {% if greeting.author %}
    <b>{{ greeting.author }}</b> wrote:
  {% else %}
    An anonymous person wrote:
  {% endif %}
  <blockquote>{{ greeting.content|escape }}</blockquote>
{% endfor %}

so what i want is: when this iterates, i need to somehow check greeting.author agains some variable that exists in javascript, and then do some other stuff. is it possible to do it?

1 Answer 1

5
{% for greeting in greetings %}
  {% if greeting.author %}
    <b>{{ greeting.author }}</b> wrote:
  {% else %}
    An anonymous person wrote:
  {% endif %}
  <blockquote>{{ greeting.content|escape }}</blockquote>
  <script type="text/javascript">
     var greeting_author = "{{ greeting.author }}";
     if(greeting_author === someVariable){
        // do other stuff here
     }
  </script>
{% endfor %}

Basically, you can just print the variable as js. Keep the type in mind (for example put "" around them for strings).

Sign up to request clarification or add additional context in comments.

1 Comment

i see. so it has to be inside the html. in other words we can't write a loop in a javascript function and iterate through greetings.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.