1

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?

Mark Nichols
  • 1,407
  • 2
  • 19
  • 25
  • {{ asin | amazon_medium_image }} doesn't work. It appears asin doesn't resolve. Also,

    {{ {{asin}} | amazon_medium_image }}

    doesn't resolve either.
    – Mark Nichols Sep 07 '11 at 19:05
  • I think the Liquid capture tag produces a string, which won't work for capturing an image, for example. For now I'll need to just copy/paste the section for each item I want to display. – Mark Nichols Sep 07 '11 at 19:09
  • 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. – Mark Nichols Sep 11 '11 at 15:17
  • See also: http://stackoverflow.com/questions/7919644/using-liquid-variables-inside-of-a-liquid-tag-call – nickf Nov 30 '11 at 23:19

1 Answers1

0

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.

Mark Nichols
  • 1,407
  • 2
  • 19
  • 25