You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jekyll技术问询:如何保留空格调用多词featured标签?

Jekyll带空格标签的Liquid调用方案

文章头部标签写法

要确保top featured被识别为单个标签(而非两个独立标签),需要用数组格式声明:

layout: post
title:
author:
categories: Jekyll
image:
tags: ["top featured"]
# 或者换行列表格式
# tags:
#   - top featured

Liquid模板调用方式

在sidebar-featured.html中,直接使用方括号包裹带空格的标签字符串来访问对应集合,替换原有的site.tags.featured:

<ol class="list-featured">
    {% for post in site.tags["top featured"] %}   
        <li class="mb-4">
            <!-- 原有内容 -->
        </li>
    {% endfor %}
</ol>

原理说明

Jekyll会将带空格的标签作为site.tags字典中的一个字符串键存储,但Liquid的点语法(site.tags.xxx)仅支持不含空格、特殊字符的标识符。用方括号+引号包裹的方式,就能直接访问包含空格的键值,完美匹配你需要保留top featured空格的需求,无需改成连字符形式。

内容的提问来源于stack exchange,提问作者Goemon Code

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 00:21:26