<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Margaret Berry</title>
    <description>The latest articles on DEV Community by Margaret Berry (@codemargaret).</description>
    <link>https://dev.to/codemargaret</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F435851%2Fd2fc1f24-4f2a-45e4-ba4f-c1fb908242cc.jpeg</url>
      <title>DEV Community: Margaret Berry</title>
      <link>https://dev.to/codemargaret</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/codemargaret"/>
    <language>en</language>
    <item>
      <title>E-commerce on the Jamstack with Bridgetown, Snipcart, and Bulma CSS</title>
      <dc:creator>Margaret Berry</dc:creator>
      <pubDate>Wed, 12 Aug 2020 17:54:19 +0000</pubDate>
      <link>https://dev.to/codemargaret/e-commerce-on-the-jamstack-with-bridgetown-snipcart-and-bulma-css-5bbc</link>
      <guid>https://dev.to/codemargaret/e-commerce-on-the-jamstack-with-bridgetown-snipcart-and-bulma-css-5bbc</guid>
      <description>&lt;p&gt;Orginally published &lt;a href="https://www.bridgetownrb.com/showcase/bulmatown-theme-and-snipcart/"&gt;here&lt;/a&gt; with more screenshots.&lt;/p&gt;

&lt;p&gt;Hello! Guest author Margaret here. This week I tried out the new &lt;a href="https://github.com/whitefusionhq/bulmatown"&gt;Bulmatown&lt;/a&gt; theme and experimented with adding products using &lt;a href="https://snipcart.com/"&gt;Snipcart&lt;/a&gt;. My test site is deployed &lt;a href="https://vigorous-ritchie-f43dbd.netlify.app/"&gt;here&lt;/a&gt; via Netlify, and you can take a closer look at the code &lt;a href="https://github.com/codemargaret/sparkletown"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting Started with Bridgetown
&lt;/h3&gt;

&lt;p&gt;I found Bridgetown approachable to someone with my level of experience. I have worked as a Ruby/JavaScript developer for about a year and a half, so at this point I feel like I know slightly more than nothing about programming. The Bridgetown &lt;a href="https://www.bridgetownrb.com/docs/installation"&gt;installation docs&lt;/a&gt; and &lt;a href="https://www.bridgetownrb.com/docs/"&gt;quick instructions&lt;/a&gt; were thorough and easy to follow. This is not always how it is! As a junior dev, I was constantly roaming a dense forest of terrible documentation, and this is not that! The longest part of the process was getting the requirements in place, and that’s mostly because I had to do a factory reset on my old work laptop because of reasons. Once that was done, I was able to get a basic Hello Bridgetown site up and running in a few minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Bulmatown Theme
&lt;/h3&gt;

&lt;p&gt;Bridgetown strikes a nice balance between having features that are ready-to-go and leaving room for customization. The starter site is a blank slate as far as style goes, which leaves it open for you to make it your own. This is great if you are a CSS guru and know what you like, or if you already have a brand with a strong visual presence. If styling is not your jam, &lt;a href="https://github.com/whitefusionhq/bulmatown"&gt;Bulmatown&lt;/a&gt; is a good option. &lt;/p&gt;

&lt;p&gt;With a few Terminal commands, your site will look polished enough to go on the real Internet.&lt;/p&gt;

&lt;p&gt;There are still choices within the theme and options for personalization. Bulmatown comes with a few out-of-the-box color options. I went with fuchsia, which looked great once I figured out how to spell it. I could also have gone with default (teal), rust, or fineart (black). If you prefer a different color, you can add your own custom Bulma variables. &lt;/p&gt;

&lt;h3&gt;
  
  
  Using Snipcart to Sell Products
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://snipcart.com/"&gt;Snipcart&lt;/a&gt; is a good option for adding a few products to a static site like Bridgetown. As described in the &lt;a href="https://docs.snipcart.com/v3/setup/installation"&gt;documentation&lt;/a&gt;, you need to add the Snipcart script and stylesheet, and then add specific attributes to an HTML button, or a button-like element, such as a styled link. Bridgetown content is written in markdown, and there are &lt;a href="https://stackoverflow.com/questions/40688633/how-can-i-add-a-button-in-a-md-file-with-jekyll"&gt;several ways&lt;/a&gt; to add an HTML button to a markdown file. I decided to go with plain HTML, because it seemed like the easiest format in which to read a button with several attributes. I added the public API key to a test product on my homepage, and that was that. The button and cart worked!  &lt;/p&gt;

&lt;p&gt;I went on to add Bulma class names to the button (“button”, “is-primary”) so that it matched the theme, and then added a link to the cart in the main nav. I needed to do a bit of tweaking to make sure that no part of the cart was hidden by the nav. Turns out, &lt;strong&gt;the Bulmatown nav has a z-index of 30&lt;/strong&gt;, so I set the z-index for the cart to 31.&lt;/p&gt;

&lt;h3&gt;
  
  
  Using Bridgetown Collections
&lt;/h3&gt;

&lt;p&gt;Now that I had Snipcart working for my single test product, I decided to make products a &lt;a href="https://www.bridgetownrb.com/docs/collections"&gt;collection&lt;/a&gt;. This would give me an organized, styled products page similar to the built-in Articles page, and it would also avoid some unnecessary repetition in my code.&lt;/p&gt;

&lt;p&gt;Here is the code for my products page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
layout: page
title: "Products"
---

{% for product in site.products %}
  &amp;lt;h2&amp;gt;{{ product.name }} | ${{ product.price }}&amp;lt;/h2&amp;gt;
  &amp;lt;img src="{{ product.image }}" alt="{{ product.alt }}" width="550" height="600"&amp;gt;
  &amp;lt;p&amp;gt;{{ product.description }}&amp;lt;/p&amp;gt;
  &amp;lt;p&amp;gt;{{ product.content | markdownify }}&amp;lt;/p&amp;gt;
  &amp;lt;button class="button is-primary buy-button snipcart-add-item"
    data-item-id="{{ product.data_item_id }}"
    data-item-price="{{ product.price }}"
    data-item-url="/products"
    data-item-description="{{ product.description }}"
    data-item-image="{{ product.image }}"
    data-item-name="{{ product.name }}"&amp;gt;
    Add to Cart
  &amp;lt;/button&amp;gt;

{% endfor %}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And here’s an example product:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;---
name:  "100% Real Diamond"
image: "/images/diamond.jpg"
alt: "diamond"
price: "9.95"
description: "This genuine diamond is a steal at $9.95! But definitely not stolen haha!"
data_item_id: "1"
---
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Anything added below the second three dashes of a product (or any collection item) can be accessed with &lt;em&gt;product.content&lt;/em&gt;. For example, I would have put the description in the content area if it were longer, or needed more formatting that would work better in markdown, but this setup was sufficient for my purposes. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Bridgetown, &lt;em&gt;id&lt;/em&gt; is a protected word&lt;/strong&gt;, which I discovered by accident when I tried to add &lt;em&gt;id&lt;/em&gt; as a property of a product. When I inspected the button in the console, instead of &lt;em&gt;1&lt;/em&gt;, the id was &lt;em&gt;products/diamond/&lt;/em&gt;, the URL for the individual product page. Changing the name to &lt;em&gt;data_item_id&lt;/em&gt; fixed the issue. My test products didn’t have enough product information to warrant individual product pages, but if they did, I could have linked the title with &lt;em&gt;product.id&lt;/em&gt; or &lt;em&gt;product.url&lt;/em&gt; like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{% for product in site.products %}
&amp;lt;h2&amp;gt;&amp;lt;a class="is-decorationless" href="{{ product.id }}"&amp;gt;{{ product.name }}&amp;lt;/a&amp;gt;&amp;lt;/h2&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;One advantage of using Bulmatown with a Bridgetown site is that you are adding on a theme rather than trying to override an existing one. This is an issue with Jekyll mentioned in the Closing Thoughts section at the very end of this article. The Bulmatown theme is a good way to quickly get some base styles in place on your Bridgetown site.&lt;/p&gt;

&lt;p&gt;Bridgetown can be effectively used for a small amount of e-commerce. Snipcart is one good option. It is easy to get started with it, and it plays well with Bridgetown.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>css</category>
      <category>webpack</category>
    </item>
  </channel>
</rss>
