Skip to content

Instantly share code, notes, and snippets.

@kevinmpowell
Last active November 11, 2016 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinmpowell/2435c4f4e9baa44b8a6c874925bb19c2 to your computer and use it in GitHub Desktop.
Save kevinmpowell/2435c4f4e9baa44b8a6c874925bb19c2 to your computer and use it in GitHub Desktop.
Nunjucks component macro - NOTE: Had to use .twig file extension since Github Gists don't support .njk :(
{% macro hero(
title="We Are Awesome",
background_image="http://placehold.it/1000x400",
cta_text="Find Out Why!",
cta_href="/some/awesome-link.html"
) %}
<div class="hero" {% if background_image %} style="background-image:url({{ background_image }})" {% endif %}>
<h1 class="hero__title">{{ title }}</h1>
{% if caller %}
{{ caller() }}
{% endif %}
<a class="hero__cta button button--primary" href="{{ cta_href }}>{{ cta_text }}</a>
</div>
{% endmacro %}
{# usage, rapid prototyping #}
{{ hero() }}
{# something with some context #}
{{ hero(title="We're super cool at that thing we do.") }}
{# passing in an html block #}
{% call hero(title="Three reasonse we're the best:") %}
<div class="grid-row">
<div class="grid-column-4">
<h2>Industry Leadership</h2>
</div>
<div class="grid-column-4">
<h2>Marketing Buzzword</h2>
</div>
<div class="grid-column-4">
<h2>Cause we said so.</h2>
</div>
</div>
{% endcall %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment