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?
Liquid is a template language that allows us to display data in a template. Liquid has constructs such as output, logic, loops and deals with variables. Liquid files are a mixture of HTML and Liquid code, and have the . liquid file extension.
Jekyll uses the Liquid templating language to process templates. Generally in Liquid you output content using two curly braces e.g. {{ variable }} and perform logic statements by surrounding them in a curly brace percentage sign e.g. {% if statement %} .
Liquid syntax is a template language used in many web applications. In Current RMS, use Liquid syntax to place dynamic content and modify data in document layouts and discussion templates. In Liquid, there are three types of code: objects, tags, and filters.
Jekyll is a static site generator, a command-line tool that creates websites by merging templates with content files. Jekyll uses Liquid as its template language, and adds a few objects, tags, and filters.
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With