开发者

Resolve liquid variable inside liquid tag

开发者 https://www.devze.com 2023-04-01 06:23 出处:网络
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

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>

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.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号