是否可以在javascript / jquery函数中使用jinja值

时间:2013-02-17 06:09:53

标签: javascript google-app-engine jinja2

查看google web eng示例;

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

所以我想要的是:当这个迭代时,我需要以某种方式检查greeting.author再次在javascript中存在一些变量,然后做一些其他的东西。 是可以做到的吗?

1 个答案:

答案 0 :(得分:3)

{% 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 %}

基本上,您可以将变量打印为js。记住这种类型(例如,为了字符串将""放在它们周围)。