title: Django: How can I use a variable inside an if statement in the template?
body: <p>My views.py hands over a variable called "preSelect" that contains a Integer value.</p>
  
  <p>Inside the template I want to use that Integer in an If statement to check if the current for loop counter is less equal or greater than than my value.</p>
  
  <pre><code>{% if forloop.counter &lt;= {{ preSelect }} %}
      &lt;td&gt;&lt;input type="checkbox" name="checks" id="1" value={{ row.0 }} checked/&gt;&lt;/td&gt;
  {% else %}
     &lt;td&gt;&lt;input type="checkbox" name="checks" id="1" value={{ row.0 }} /&gt;&lt;/td&gt;
  {% endif %}
  </code></pre>
  
  <p>This however returns me the following error:</p>
  
  <blockquote>
    <p>Environment:</p>
    
    <p>Request Method: POST Request URL: <a href="http://127.0.0.1:8000/" rel="noreferrer">http://127.0.0.1:8000/</a></p>
    
    <p>Django Version: 1.10.2 Python Version: 2.7.11 Installed Applications:
    ['django.contrib.admin',  'django.contrib.auth', 
    'django.contrib.contenttypes',  'django.contrib.sessions', 
    'django.contrib.messages',  'django.contrib.staticfiles', 
    'testsetcreation'] Installed Middleware:
    ['django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware']</p>
    
    <p>Template error: In template
    D:\Django\testsetcreation\templates\testsetcreation\testsetView.html,
    error at line 61    Could not parse the remainder: '{{' from '{{'   51
    :                     Comment    52 :<br>
    SW Version    53 :                     HW Version<br>
    54 :                     ABP    55 :<br>
    Project    56 :                     57 :<br>
        58 :                 59 :             {% for row in
    rows %}    60 :                     61 :                      {%
    if forloop.counter &lt;= {{ preSelect }} %}     62 :<br>
        63 :                     {% else %}    64 :<br>
        65 :                     {% endif %}    66 :<br>
    {{ row.1 }}    67 :                     {{ row.2 }} 
    68 :                         69 :<br>
        70 :                         {{
    row.3 }}    71 :                         </p>
    
    <p>Traceback:</p>
    
    <p>File "c:\Python27\lib\site-packages\django\core\handlers\exception.py"
    in inner
      39.             response = get_response(request)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\core\handlers\base.py" in
    _get_response
      187.                 response = self.process_exception_by_middleware(e, request)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\core\handlers\base.py" in
    _get_response
      185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)</p>
    
    <p>File "D:\Django\testsetcreation\views.py" in testsetView
      102.     return render(request, 'testsetcreation/testsetView.html', context)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\shortcuts.py" in render
      30.     content = loader.render_to_string(template_name, context, request, using=using)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\loader.py" in
    render_to_string
      67.         template = get_template(template_name, using=using)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\loader.py" in
    get_template
      21.             return engine.get_template(template_name)</p>
    
    <p>File
    "c:\Python27\lib\site-packages\django\template\backends\django.py" in
    get_template
      39.             return Template(self.engine.get_template(template_name), self)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\engine.py" in
    get_template
      160.         template, origin = self.find_template(template_name)</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\engine.py" in
    find_template
      134.                         name, template_dirs=dirs, skip=skip,</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\loaders\base.py"
    in get_template
      44.                     contents, origin, origin.template_name, self.engine,</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\base.py" in
    <strong>init</strong>
      191.         self.nodelist = self.compile_nodelist()</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\base.py" in
    compile_nodelist
      233.             return parser.parse()</p>
    
    <p>File "c:\Python27\lib\site-packages\django\template\base.py" in parse
      518.                     raise self.error(token, e)</p>
    
    <p>Exception Type: TemplateSyntaxError at / Exception Value: Could not
    parse the remainder: '{{' from '{{'</p>
  </blockquote>