解决液体标签内的液体变量 [英] Resolve liquid variable inside liquid tag

查看:93
本文介绍了解决液体标签内的液体变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Octopress,这是Jekyll渲染我的网站的框架.我正在使用包装ruby-aaws gem的插件,允许使用Amazon的产品标识符(asin)查询Amazon.我想使页面的一部分具有吸引力,循环遍历asins列表以产生输出.到目前为止,这是我的代码:

I'm using Octopress, which is a framework for Jekyll to render my site. I'm using a plugin which wraps the ruby-aaws gem, allowing queries to Amazon using Amazon's product identifier (asin). I'd like to render a portion of the page recusively, looping through a list of asins to produce the output. Here's my code so far:

<section>
  <h1>Recent Diversions</h1>
  {% for asin in ["044656432X", "0743276396", "B001YT048E"] %}
    {% capture a_image %}{{ asin | amazon_medium_image }}{% endcapture %}
    {% capture a_link %}{{ asin | amazon_link }}{% endcapture %}
    {% capture a_authors %}{{ asin | amazon_authors }}{% endcapture %}

    <p>{{ a_image }}</p>
    <p>{{ a_link }} by {{ a_authors }}</p>
  {% endfor %}
</section>

我的理解是{%Capture variable_name%} ... {%endcaputre%}渲染封装的内容,并将结果分配给variable_name.但是,当我生成站点时,什么也不会生成.如果我将单个asin替换为捕获标签中的asin引用,则页面将正确呈现.

My understanding is the {% capture variable_name %}...{% endcaputre %} renders what is encapsulated and assigns the result to variable_name. However, when I generate the site nothing is generated. If I substitue a single asin for the asin references within the capture tags the page renders properly.

我应该如何正确引用捕获标记中的asin变量以使其正常工作?

How should I properly reference the asin variable inside the capture tag to make this work?

推荐答案

我终于解决了这个问题.上面显示的代码在一个名为aws.html的文件中,该文件包含在该站点的主要index.html中.似乎Liquid不允许在该级别进行变量分配.当我将变量赋值移动到_config.yml文件(即asins):["044656432X","0743276396","B001YT048E"]时,以上代码可以正常工作.

I have finally sorted this out. The code shown above is in a file called aws.html, which is included in the main index.html for the site. It seems that Liquid doesn't allow variable assignments at that level. When I move the variable assignment to the _config.yml file, i.e., asins: ["044656432X", "0743276396", "B001YT048E"] then the code above works perfectly.

这篇关于解决液体标签内的液体变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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