Skip to content

Instantly share code, notes, and snippets.

@gmocamilotd
Created September 23, 2019 20:31
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 gmocamilotd/05340dd0f05680bcd5b9381744753efb to your computer and use it in GitHub Desktop.
Save gmocamilotd/05340dd0f05680bcd5b9381744753efb to your computer and use it in GitHub Desktop.
Considere
```
# base.html template
{% macro coffeestore(name, id='', address='', city='San Diego', state='CA', email=None) -%}
<a id="{{id}}"></a>
<h4>{{name}}</h4>
<p>{{address}} {{city}},{{state}}</p>
{% if email %}<p><a href='mailto:{{email}}'>{{email}}</a></p>{% endif %}
{%- endmacro %}
```
```
# index.html template calls inherited macro directly
{% extends "base.html" %}
{{coffeestore('Downtown',1,'Horton Plaza','San Diego','CA','downtown@coffeehouse.com')}}
```
```
# detail.html template with no extends, uses {% import %} to access macro in base.html
{% import 'base.html' as base %}
{{base.coffeestore('Downtown',1,'Horton Plaza','San Diego','CA','downtown@coffeehouse.com')}}
```
```
# otherdetail.html template with no extends, uses {% from import %} to access macro in base.html
{% from 'base.html' import coffeestore as mycoffeestoremacro %}
{{mycoffeestoremacro('Downtown',1,'Horton Plaza','San Diego','CA','downtown@coffeehouse.com')}}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment