Working with data from external api #454
-
Hello guys, I'm sorry to write another post here, but I really can't find much information on internet yet... I'd really appreciate it if you can give me a little guidance here. ContextI'm using bridgetown edge, based on this article. I created a collection called SetupMy ...
pagination:
enabled: true
per_page: 10
template_engine: erb
collections:
shops:
output: true
permalink: /shops/:slug
sort_by: name
sort_direction: ascending
I created this builder: class Builders::LoadOffersFromApi < SiteBuilder
def build
get "https://my-super-endpoint.com/shops.json" do |data|
data.each_with_index do |brand, index|
add_resource :shops, "#{brand[:slug]}.erb" do
layout :shops
id brand[:id]
name brand[:name]
slug brand[:slug]
description brand[:description]
position index
end
end
end
end Then, I have the template for the list of the shops, at ---
layout: default
pagination:
collection: shops
---
<h1>All shops</h1>
<% paginator.resources.each do |shop| %>
<a href="<%= shop.relative_url %>">
<%= shop.data.name %>
</a>
<% end %> And I also created a layout for rendering the pages for each shop, at ---
layout: default
---
<h1>Shop: <%= page.data.name %></h1> I also created the layout called Problems
That's it. I'd really appreciate any guidance. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
Looks pretty solid at first glance! I think regarding the raw html issue you'd need to change the permalink to either Not sure why the ordering isn't working tho… |
Beta Was this translation helpful? Give feedback.
Looks pretty solid at first glance! I think regarding the raw html issue you'd need to change the permalink to either
/shops/:slug/
or/shops/:slug.*
(depending on if you want the URL to end with a slash or not)Not sure why the ordering isn't working tho…