1

所以,我有一个从集合中获取数据的模板,这个特定的集合包含一些字体的信息,我需要输出一个语法突出显示的代码块,这个代码引用了应该如何添加字体@fontface,例如:

           {% highlight css %}
            @font-face 
                font-family: coolFont;
                src: url(/fonts/coolFont.woff) format("woff"),
              url(fonts/coolFont.ttf) format('truetype');
                  font-weight: normal;
                font-style: normal;
                font-display: swap;
            }
            {% endhighlight %}

我希望从帖子前端传递字体名称,并将其与每个循环一起输出,但是,因为它在<code>输出我的液体标签时呈现,而不是前端数据。

            {% highlight css %}
            @font-face 
                font-family: {{ post.data.fontName }};
                src: url(/fonts/{{post.data.fontName}}.woff) format("woff"),
              url(fonts/{{post.data.fontName}}.ttf) format('truetype');
                  font-weight: normal;
                font-style: normal;
                font-display: swap;
            }
            {% endhighlight %}

有没有办法“逃脱”括号?

4

1 回答 1

0

你可能对 Github repo 中的这个问题感兴趣。eleventy-plugin-syntaxhighlight

本质上,{% highlight %}标签内的 Liquid 模板不起作用,但您可以通过切换到 Nunjucks 模板(模板将在块内工作)或通过定义自定义配对短代码来解决它,您可以直接使用 Prism 或您选择的荧光笔.

于 2021-05-28T22:13:00.327 回答