Ellis Michael
Ellis Michael

Reputation: 972

Macro in Liquid Template language

I'm using Jekyll, which uses the Liquid Template language. I've used Jinja templating in the past, and it has the concept of a macro (just a named function). Does Liquid have something which provides equivalent functionality? If not, is there some Jekyll plugin which will extend Liquid to provide it?

Upvotes: 7

Views: 2605

Answers (2)

Erik Gillespie
Erik Gillespie

Reputation: 3959

You can create includes that accept parameters. It's not quite a macro but it's what I've used successfully on GitHub Pages.

More details and tips for managing includes and using parameters can be found in the Jekyll documentation.

Here's an example:

_includes/email_link.html

<a href="mailto:{{ include.user.email_address }}"
   title="Email {{ include.user.name }}">
    <i class="fa fa-fw fa-envelope"></i>
</a>

about.md

---
layout: page
title: About
---
{% include email_link.html user=site.users.erik %}

_config.yml

users:
    erik:
        name: Erik
        email_address: [email protected]

Upvotes: 12

David Jacquel
David Jacquel

Reputation: 52829

This is exactly what Jekyll tags plugins are made for.

Upvotes: 2

Related Questions