-
Hey, I've been using 11ty for a while with tremendous success but have found a bit of a snag recently trying to do something more ambitious (for me). I am making a price comparison website. I scrape each website I monitor and have an API available with the results, per website (using simplescraper.io) Inside the "_data" folder, I have a .js file for each website's API. Example:
Now, I make a folder "website1", where I paginate over website1's JSON from the API call. Example:
11ty is nicely paginating the JSON, but I need to put everything inside a global collection. Reason is, I have to scrape by website, but I'm hoping to access all products with Nunjucks and sort by their price in a "lowest to highest" list for the consumer to choose the cheapest option. Because my JS skills are close to none, I have tried to add the
To access it on index.njk like this, for example:
However, this results in the following output:
Could you please help me see what I'm doing wrong here? I realize there might be a more elegant solution but like I said, I'm self taught and just barely scraping by. Thank you for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
When using pagination, I like to use the Also, doesn't look like you're setting explicit permalinks, so I'm not sure how many files are being written out and what the structure of that is. But from your output, it looks like you have 18 items in the Another trick I like to use is a special filter for dumping objects out into JSON strings for easier debugging. // .eleventy.js
eleventyConfig.addFilter("toJson", (value, pretty=2) => JSON.stringify(value, null, pretty)); That doesn't always play nice w/ collections and complex Eleventy data due to circular references, so another handy one is: // .eleventy.js
const inspect = require("util").inspect;
//...
eleventyConfig.addFilter("inspect", value => inspect(value)); Then you should be able to do something like this to debug the contents of each of the objects in the collections in question (versus the less helpful "[object Object]"): <pre>
{{ collections.testtag | inspect }}
</pre> |
Beta Was this translation helpful? Give feedback.
When using pagination, I like to use the
alias
key as well to make it easier for me to remember the current pagination item. https://www.11ty.dev/docs/pagination/#aliasing-to-a-different-variableAlso, doesn't look like you're setting explicit permalinks, so I'm not sure how many files are being written out and what the structure of that is. But from your output, it looks like you have 18 items in the
all
collection. You could probably also output thecollections.testtag
variable and see if that has 18 items, or if you have multiple different websites and each one has a few different pages/collections.Another trick I like to use is a special filter for dumping objects out into JSON strin…