Jekyll前端事项中的自定义变量 [英] Custom Variables in Jekyll Front Matter

查看:38
本文介绍了Jekyll前端事项中的自定义变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jekyll的新手,想知道是否可以在Jekyll Front Matter中包括自定义变量.这对于嵌套布局很有用,例如:

New to Jekyll and wondering if it's possible to include custom variables in Jekyll Front Matter. It would be useful for nested layouts, for example something like:

layouts/artist.html

layouts/artist.html

----
layout: default
title: {{ page.artist }} (Artist)
----

尝试此操作时出现错误.

I get an error trying that.

推荐答案

目前,Jekyll不支持前端变量Liquid,唯一的方法是通过插件,例如 jekyll-conrefifier .

At the moment, Jekyll do not support Liquid variables in the front matter, and the only way to do that would be through a plugin, such as jekyll-conrefifier.

或者,您可以做的是创建在同一文件中重复使用的变量:

Alternatively, what you can do, though, is create variables that you re-use on the same file:

{% assign new_title = page.title | append: " (Artist)" %}
<h1>{{ new_title }}</h1>

,您还可以将变量传递到包含的文件中.例如,包括来自_includes\display-post.html的文件,该文件将修改后的标题作为参数传递:

and you can also pass variables to files that get included. For example, including a file from _includes\display-post.html passing the modified title as an argument:

{% assign new_title = page.title | append: " (Artist)" %}
{% include display-post.html post_title=new_title %}

然后获取传入的值的值(_includes\display-post.html的示例内容):

And then getting the value of the value passed in (example content of _includes\display-post.html):

{% assign title_received = include.post_title %}

<h1>Title that as passed in: {{ title_received }}</h1>

这篇关于Jekyll前端事项中的自定义变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆