title: Jinja2: Custom filter boolean flag
body: <p>I'm trying to follow back this example here:</p>
  <p><a href="https://stackoverflow.com/questions/25449879/embed-custom-filter-definition-into-jinja2-template">Embed custom filter definition into jinja2 template?</a></p>
  <p>but instead of doing upperstring, I would like to do a boolean flag.</p>
  <p>In my jinja2 template, I would like something like this:</p>
  <pre><code>{{ set | remediate }} /etc/network/interfaces
  </code></pre>
  <p>I would like it to print 'set' if remediate flag is set to false. When I render, the expected output is:</p>
  <pre><code>set /etc/network/interfaces
  </code></pre>
  <p>If the remediate flag is set to true, it will NOT print 'set' when rendered:</p>
  <pre><code>/etc/network/interfaces
  </code></pre>
  <p>Using back the example from the link, is there a way I can pass the boolean flag into the function so that when I define it using <code>env.filters['remediate'] = remediate</code> it will determine whether to output 'set' or not when rendered?</p>
  <p><em><strong>render_config.py</strong></em></p>
  <pre><code>from render import render
  
  def main():
    flag = False
    render(flag)
  </code></pre>
  <p><em><strong>render.py</strong></em></p>
  <pre><code>def render(flag):
  
     import jinja2
  
     loader = jinja2.FileSystemLoader('/tmp')
     env = jinja2.Environment(autoescape=True, loader=loader)
  
     env.filters['remediate'] = remediate
     temp = env.get_template('test.jinja2')
     temp.render(set='set')
  
  def remediate(flag):
     &quot;&quot;&quot;Custom filter&quot;&quot;&quot;
     return flag
  </code></pre>