Is there a way to evaluate string with liquid tags

回眸只為那壹抹淺笑 提交于 2019-12-10 18:17:17

问题


I need to provide page content reference list (it should contain references on sections on page). The only way which I can see is to use page.content and parse it, but I stumbled on problem with data evaluation. For example I can pull out this string from page.content: {{site.data.sdk.language}} SDK but there is no way to make jekyll process it, it outputs as is. Also I want to make it possible to create cross-pages links (on specific section on page, but that link generated by another inclusion and doesn't persist in page.content in HTML form).

Is there any way to make it evaluate values from page.content?

P.S. I'm including piece of code which should build page content and return HTML with list (so there is no recursions). P.P.S. I can't use submodules, because I need to run this pages on github pages.

Thanks.


回答1:


Shouldn't {{ site.data.sdk.language | strip_html }} do it? I don't know, most probably I didn't understand the problem. Can you elaborate more? Maybe provide a link to a post you're referring to?




回答2:


Thinking about the similar

{% assign title = site.data.sdk.language %}

which is a stock Liquid tag and does the job well, so instead of

{% section title={{site.data.sdk.language}} %}

write your code as

{% section title = site.data.sdk.language %}

The key here is that once you enter {%, you're in Liquid. Don't expect Liquid to go "Inception" all over itself. {{ is just a shorthand for "print this to output", but an parameter passing is not output, it's just reading a variable.

You should be able to also go wild and do:

{% section title = site.data.sdk.language | capitalize %}

For more re-read the docs: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers



来源:https://stackoverflow.com/questions/20914071/is-there-a-way-to-evaluate-string-with-liquid-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!