Created
September 23, 2019 20:31
-
-
Save gmocamilotd/05340dd0f05680bcd5b9381744753efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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