Skip to content

Instantly share code, notes, and snippets.

@natw
Created February 7, 2011 16:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natw/814607 to your computer and use it in GitHub Desktop.
Save natw/814607 to your computer and use it in GitHub Desktop.
from jinja2 import Template
source = """
{%- set foo = 'hello' -%}
{%- macro bar(things, oid, attribute) -%}
{%- for thing in things -%}
{%- if thing.offer_id == oid -%}
{{attr thing attribute}}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{% set foo = bar(widgets) %}
{{ foo }}
{{ foo }}
{{ foo }}
"""
template = Template(source)
widgets = (1, 2, 3, 4)
rendered = template.render(widgets=widgets)
print rendered
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment