<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tetsuro Takara&#039;s Blog &#187; Shopify</title>
	<atom:link href="http://blog.tetsutakara.com/category/shopify/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tetsutakara.com</link>
	<description>Tetsuro&#039;s Blog</description>
	<lastBuildDate>Fri, 16 Jul 2010 14:36:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Creating a Threadless-like Add-to-Cart button using jQuery and AJAX</title>
		<link>http://blog.tetsutakara.com/1156/creating-a-threadless-like-add-to-cart-button-using-jquery-and-ajax/</link>
		<comments>http://blog.tetsutakara.com/1156/creating-a-threadless-like-add-to-cart-button-using-jquery-and-ajax/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 15:18:10 +0000</pubDate>
		<dc:creator>Tetsuro</dc:creator>
				<category><![CDATA[Shopify]]></category>

		<guid isPermaLink="false">http://blog.tetsutakara.com/?p=1156</guid>
		<description><![CDATA[In this tutorial we will be modifying the product page of the Ripen theme to work more like the product page on Threadless. We&#8217;re going to be modifying the Ripen theme, but this tutorial is applicable to any Shopify theme. I would like to thank John Tajima again for teaching me how AJAX and JSON [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial we will be modifying the product page of the Ripen theme to work more like the product page on <a href="http://www.threadless.com/" target="_blank">Threadless</a>. We&#8217;re going to be modifying the Ripen theme, but this tutorial is applicable to any Shopify theme. I would like to thank <a href="http://www.tajimaphotography.com/" target="_blank">John Tajima</a> again for teaching me how AJAX and JSON objects work with Shopify. We will also make it so that the number of products in the cart displayed automatically updates after you add an item to the cart. </p>
<p><object width="588" height="354"><param name="movie" value="http://www.youtube.com/v/lurhciqVDTQ&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/lurhciqVDTQ&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="588" height="354"></embed></object></p>
<div class="sub">A quick demo of the completed theme in action</div>
<p><span id="more-1156"></span></p>
<h2 class="steps">1. Install jQuery</h2>
<p>If you are unsure of how to do this, please see Steps 1 to 3 from <a href="http://blog.tetsutakara.com/593/shopify-tutorial-making-sure-a-user-agrees-to-the-terms-conditions-using-jquery/">this tutorial.</a></p>
<h2 class="steps">2. Install Colorbox</h2>
<p>Grab the jQuery plugin Colorbox <a href="http://colorpowered.com/colorbox/">here</a>, and upload it to your theme assets. We&#8217;re going to be using Colorbox to get the lightbox popup when a product is added to the cart. I usually use Fancybox for lightboxes, but I decided to go with Colorbox for this tutorial because it <em>&#8220;can be called directly, without assignment to an element&#8221;</em>. This means that I can call a Colorbox method, and create a lightbox on-the-fly when the &#8220;Add to Cart&#8221; button is clicked, but with Fancybox this would be impossible.</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2010/07/thread1-588x272.png" alt="thread1" title="thread1" width="588" height="272" class="alignnone size-medium wp-image-1175" /></p>
<div class="sub">In your theme assets, you should have &#8220;jquery.colorbox-min.js&#8221; and &#8220;colorbox.css&#8221;. </div>
<p>Be sure to add these two files in the &lt;head&gt; section to your theme.liquid as well.</p>
<pre>
<code>&lt;head&gt;
     <span style="color:blue;">...other assets</span>
     {{ 'colorbox.css' | asset_url  | stylesheet_tag }}
     {{ 'jquery.colorbox-min.js' | asset_url | script_tag }}
&lt;/head&gt;</code>
</pre>
<h2 class="steps">3. Modify the &#8220;Add to Cart&#8221; button</h2>
<p>Open your product.liquid file, and locate the input button for adding to the cart. The input button looks like this:</p>
<pre>
<code> &lt;input type="submit" name="add" value="Add to Cart" id="add" /&gt;</code>
</pre>
<p>We want to do two things to this button: first, we want to make it so that even if the user clicks on it, the user is not taken to the cart page. Second, we want to call a custom function (that we&#8217;re going to be writing shortly) that makes an AJAX call to add the product to the cart. </p>
<pre>
<code> &lt;input type="submit" name="add" value="Add to Cart" id="add" <span style="color:red;">onclick="return false; addItem('add-to-cart');"</span>/&gt;</code>
</pre>
<p>The addItem function takes the form&#8217;s id as a parameter. This is so that when we use jQuery later, we know which form to select. The opening tag for your form should look like this:</p>
<pre>
<code>&lt;form action="/cart/add" method="post" id="add-to-cart"&gt; </code>
</pre>
<h2 class="steps">4. Preparing product.liquid</h2>
<p>Add the following line at the top of product.liquid. </p>
<pre>
<code>&lt;div id="added-box-wrapper" style="display:none;"&gt;
    &lt;div id="added-box"&gt;&lt;/div&gt;
&lt;/div&gt;</code>
</pre>
<p>The added-box is where the content of the lightbox will be inserted. We need to wrap it in another div with a &#8220;display:none;&#8221; so that the content of the lightbox are not displayed on the actual page. </p>
<h2 class="steps">5. Preparing theme.liquid</h2>
<p>Next, we have to modify theme.liquid a little so that the number displayed for the number of items in the cart updates automagically. In theme.liquid, find a place where you want to show a link to the cart. In this tutorial, I&#8217;m going to put it in the right column, under where it says &#8220;Shopping Cart&#8221;. </p>
<pre>
<code>&lt;a href="/cart" id="cart-number"&gt;
    {% if cart.item_count == 0 %}
       Your cart is empty.
    {% endif %}
&lt;/a&gt;    </code>
</pre>
<p>What&#8217;s important here is that the &lt;a&gt; tag has the id &#8220;cart-number&#8221;, so that we can select it with jQuery later to modify its contents.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tetsutakara.com/1156/creating-a-threadless-like-add-to-cart-button-using-jquery-and-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Shopify Tutorial: Adding a Barchart for Inventory Using jQuery and JSON Objects</title>
		<link>http://blog.tetsutakara.com/652/adding-a-barchart-for-inventory-using-jquery-and-json-objects/</link>
		<comments>http://blog.tetsutakara.com/652/adding-a-barchart-for-inventory-using-jquery-and-json-objects/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 16:12:37 +0000</pubDate>
		<dc:creator>Tetsuro</dc:creator>
				<category><![CDATA[Shopify]]></category>

		<guid isPermaLink="false">http://blog.tetsutakara.com/?p=652</guid>
		<description><![CDATA[I was looking at t-shirts at an online store one day, and it had a nice little bar chart that displayed how much of each size it had left. I thought to myself, &#8220;I wonder if this is doable in Shopify?&#8221;. The answer is yes, thanks to jQuery and JSON Objects. In this tutorial, I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>I was looking at t-shirts at an online store one day, and it had a nice little bar chart that displayed how much of each size it had left. I thought to myself, &#8220;I wonder if this is doable in Shopify?&#8221;. The answer is yes, thanks to jQuery and JSON Objects. In this tutorial, I&#8217;ll be showing you how to add a bar chart in your product page that shows how much of each variant you have left in a bar chart. A big thank you to Javascript wizard <a href="http://www.tajimaphotography.com" title="John Tajima Photography">John Tajima</a> for introducing me to JSON objects and helping me out with the Javascript portion of this tutorial. </p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/Screen-shot-2009-11-22-at-6.13.52-PM.jpg" alt="Screen-shot-2009-11-22-at-6.13.52-PM" title="Screen-shot-2009-11-22-at-6.13.52-PM" width="588" height="359" class="alignnone size-full wp-image-719" /></p>
<div class="sub">The bar chart integrated into the <em>Moderno</em> theme.</div>
<p>Implementing this feature can be done in three easy steps: adding the HTML/Liquid, adding the Javascript, and then adding the CSS. You can also fully customize the look of the bar chart with CSS. This bar chart will work for <em>any</em> theme, as long as you insert the HTML, Liquid, Javascript and CSS properly.<br />
<span id="more-652"></span><br />
Keep in mind that this code will only work if you&#8217;re tracking the inventory levels of your product&#8217;s variant. In order to enable inventory tracking, you must navigate to your Product details page, and scroll down to where it lists the variants. Click the &#8216;edit&#8217; link next to the variants, and in the dropdown menu, select &#8220;Shopify tracks this variant&#8217;s stock level&#8221;. Finally, enter the inventory level for this variant.</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/Screen-shot-2009-12-10-at-12.09.34-AM.png" alt="Screen shot 2009-12-10 at 12.09.34 AM" title="Screen shot 2009-12-10 at 12.09.34 AM" width="588" height="339" class="alignnone size-full wp-image-898" /></p>
<h2 class="steps">The way it works:</h2>
<p>The algorithm is best explained with an example. You have a t-shirt with 3 variants: small, medium, large. Let&#8217;s say you have 2 smalls, 4 mediums, and 4 larges. </p>
<p>The Javascript code will first calculate the total inventory level for ALL variants &#8211; in this example, the total will be 10 (2 smalls + 4 mediums + 4 larges = 10). Then, for each variant, it will calculate the percentage of a single variant&#8217;s inventory level versus. the total inventory level. This percentage is then used to determine the width of each bar. The percentages in our t-shirt example would be 20% for small, 40% for medium, and 40% for large, and the CSS will fill in the black bars accordingly. </p>
<h2 class="steps">1. Download jQuery and put it in the theme.</h2>
<p>If you are unsure of how to do this, please see Steps 1 to 3 from my <a href="http://blog.tetsutakara.com/593/shopify-tutorial-making-sure-a-user-agrees-to-the-terms-conditions-using-jquery/">last tutorial.</a></p>
<h2 class="steps">2. Insert the HTML/Liquid code inside of Product.liquid.</h2>
<p>This is the code that is used to display the bar chart. Paste this code inside product.liquid where you want to output the bar chart. </p>
<pre>
<code>{% if product.variants.size &gt; 1 %}
  &lt;div id="inventory"&gt;
    {% for variant in product.variants %}
      &lt;div class="inventory-item"&gt;
        <span>{{ variant.title }}</span>&lt;br/&gt;
        &lt;div class="inventory-bar"&gt;
          &lt;div class="filler variant_{{forloop.index0}}"&gt;&amp;nbsp;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    {% endfor %}
  &lt;/div&gt;
{% endif %}</code>
</pre>
<p>The code above first checks if the product has more than one variant. The bar chart will only show if there is more than one variant, because there is not much point in making a bar chart if there is only one bar to show. </p>
<p>Next, the for-loop creates a div with the class &#8220;inventory-bar&#8221; for each variant. The &#8220;inventory-bar&#8221; div has a gray background has a width of 100% (which means that it will be the width of the &#8220;inventory&#8221; div. The div within &#8220;inventory-bar&#8221; is the black &#8216;filler&#8217; bar that will expand its width depending on how much inventory for the variant is available. The filler bar is assigned a width in percentage by the Javascript in Step 3. </p>
<p>The next function then takes the inventory level of each variant, and assigns the CSS property &#8216;width&#8217; in percentage. The percentage is calculated by dividing the variant&#8217;s inventory level by the total inventory, and then multiplying the result by 100. Using jQuery, the class variant_i (where &#8216;i&#8217; is the index number of the loop) is assigned an inline style with the calculated width. </p>
<h2 class="steps">3. Insert the Javascript/jQuery code.</h2>
<p>Below the code from Step 2, insert the following Javascript/jQuery code. </p>
<pre>
<code>&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($){
  var product_json = {{ product | json }};
  // get total inventory of product
  var total_inventory = 0;
  jQuery.each(product_json.variants, function(i, v) {
    total_inventory += v.inventory_quantity
  });
  // replace inventory bars for variants
  jQuery.each(product_json.variants, function(i, v){
    var count = v.inventory_quantity;
    if (count == 0) {
      $('.variant_'+i).css({'background':'none'}).html('<span class="message">Sold Out</span>');
    } else {
      $('.variant_'+i).css({'width': ((count / total_inventory)*100) + "%"});
    }
  });
});
&lt;/script&gt;</code>
</pre>
<p>The code above  first creates a JSON object of the product that you are currently viewing, using Liquid&#8217;s &#8220;json&#8221; filter. We want to convert the product into a JSON object because it will allow us to use Javascript for calculations (unfortunately, Liquid alone is not sufficient, as it does not have many math functions). </p>
<p>Next, it loops through each of the variants of the product, and calculates the total of all variant inventories and stores them in a variable called total_inventory.</p>
<p>The last function takes the inventory level of each variant, and assigns the CSS property ‘width’ in percentage. The percentage is calculated by dividing the variant’s inventory level by the total inventory, and then multiplying the result by 100. Using jQuery, the class variant_i (where ‘i’ is the index number of the loop) is assigned an inline style with the calculated width. The CSS class variant_i is matched up with the variant_{{forloop.index0}} in the for-loop from the HTML code in Step 2, which ensures that the right width is assigned to the right variant. </p>
<p>However, if the variant&#8217;s inventory level is 0, the bar for the variant will not be given a width, and instead it will display a message that says &#8220;Sold Out&#8221;. </p>
<h2 class="steps">4. Insert the CSS code.</h2>
<p>Inside your CSS file, insert the following selectors for the bar chart.</p>
<pre>
<code>
#inventory{
        /*Give this div a width if you'd like to set the barcharts to a certain width. Otherwise, it will take on the width of its parent div. */
}

.filler{
	background:#000;
}

.inventory-item{
	margin-bottom:15px;
}

.inventory-bar{
	background:#e1e1e1;
	height:20px;
	width:100%;
}</code>
</pre>
<p>The simple CSS above styles the bar chart. By using your own CSS, you can customize the color, margin, width, etc. in any way that you like.</p>
<p>Here are some examples of the bar charts in action, in different themes:</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/dropify2.png" alt="dropify2" title="dropify2" width="588" height="444" class="alignnone size-full wp-image-891" /></p>
<div class="sub">The bar chart in the Dropify theme.</div>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/minimify.png" alt="minimify" title="minimify" width="588" height="476" class="alignnone size-full wp-image-895" /></p>
<div class="sub">The bar chart in the Minimify theme.</div>
<h2 class="steps">Conclusion:</h2>
<p>Originally, I had wanted to use just Liquid to accomplish this, but in the end I had to use a combination of Liquid and Javascript because Liquid cannot do many math functions. With that said I&#8217;m pretty happy that I used Javascript because I learned a great deal about JSON objects. (thanks again <a href="http://www.tajimaphotography.com" title="John Tajima Photography">John</a>!).  I hope you find this technique useful, and I hope to see this in some themes in the future!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tetsutakara.com/652/adding-a-barchart-for-inventory-using-jquery-and-json-objects/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Shopify Tutorial: Making Sure a User Agrees to the Terms &amp; Conditions Using jQuery</title>
		<link>http://blog.tetsutakara.com/593/shopify-tutorial-making-sure-a-user-agrees-to-the-terms-conditions-using-jquery/</link>
		<comments>http://blog.tetsutakara.com/593/shopify-tutorial-making-sure-a-user-agrees-to-the-terms-conditions-using-jquery/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 15:02:31 +0000</pubDate>
		<dc:creator>Tetsuro</dc:creator>
				<category><![CDATA[Shopify]]></category>

		<guid isPermaLink="false">http://blog.tetsutakara.com/?p=593</guid>
		<description><![CDATA[In this short tutorial, I will be walking you through how to prevent users from going to the checkout page unless they have agreed to the Terms and Conditions using jQuery. We&#8217;ll be doing this by adding a checkbox to the cart page, which if checked, will allow the user to go the the checkout [...]]]></description>
			<content:encoded><![CDATA[<p>In this short tutorial, I will be walking you through how to prevent users from going to the checkout page unless they have agreed to the Terms and Conditions using jQuery. We&#8217;ll be doing this by adding a checkbox to the cart page, which if checked, will allow the user to go the the checkout page. If it&#8217;s not checked, an alert box will be shown, and the user will be prevented from going to the checkout page. </p>

<h2 class="steps">1. Download jQuery</h2>

<p>You can download jQuery <a href="http://code.google.com/p/jqueryjs/downloads/detail?name=jquery-1.3.2.min.js&#038;downloadBtn=">here</a>.</p>

<h2 class="steps">2. Add jQuery to your theme assets</h2>

<p>In the Shopify backend, navigate to Assets &gt; Theme Editor. Under Theme Assets, click the Browse button, and navigate to where you saved the jQuery file from Step 1. Double click the file to upload. </p>

<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/jquery-upload-612x227.png" alt="jquery-upload" title="jquery-upload" width="588" height="218" class="aligncenter size-medium wp-image-595" /></p>
<span id="more-593"></span>
<h2 class="steps">3. Load up jQuery in theme.liquid</h2>

<p>In Theme Editor, open theme.liquid. In the &lt;head&gt; section, enter the following code.</p>

<pre>
<code>{{ 'jquery-1.3.2.min.js' |asset_url  | script_tag }}</code>
</pre>

<p>This code will load the jQuery script that you uploaded in the &lt;head&gt; section of all of your store&#8217;s pages. </p>

<h2 class="steps">4. Adding the checkbox in cart.liquid</h2>

<p>In Theme Editor, open cart.liquid. Enter the following code &#8211; this will insert a checkbox and a label to your cart page. Please make sure that the ids of the checkbox and the label are the same (I named mine &#8220;agree&#8221;). </p>

<pre>
<code>&lt;input type="checkbox" id="agree"/&gt;
&lt;label for="agree"&gt;I agree with the Terms and Conditions&lt;/label&gt;</code>
</pre>

<p>The location of where the above code goes will depend on how you want to style your cart page, but it can really go anywhere within the cart.liquid template. For this example, I&#8217;m using the Minimify theme, and I&#8217;ve placed the checkbox and its label directly above the checkout button. Here is what my cart page looks like:</p>

<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/cart-page-612x390.png" alt="cart-page" title="cart-page" width="588" height="374" class="aligncenter size-medium wp-image-596" /></p>

<p>For the next step, you&#8217;re going to need the id of the checkout button&#8217;s &lt;input&gt;. The id will be used in the jQuery code in step 5. In my example, I gave the input an id named &#8220;checkout&#8221;. </p>

<h2 class="steps">5. Enter the jQuery code</h2>

<p>The last step it to add the jQuery code that checks to see if the checkbox has been checked or not. Open theme.liquid again, and enter the following code in the &lt;head&gt; section. The id of the checkout button is labeled in red. Be sure to add a pound sign (#) before the name of your checkout button&#8217;s id.</p>

<pre>
<code>&lt;script type="text/javascript"&gt;
  $(document).ready(function(){
    $("<span style="color:red;">#checkout</span>").click(function(){
      if($('#agree').is(':checked')){
        $("<span style="color:red;">#checkout</span>").submit();
      }
      else{
        alert("Please agree to the Terms and Conditions");
        return false;
      }
    });
  });
&lt;/script&gt;</code>
</pre>

<p>$(&#8220;#checkout&#8221;).click(function(){}); is a function that runs whenever the input with the id &#8220;checkout&#8221; is clicked. It then checks if the checkbox with id &#8220;agree&#8221; is checked or not. If it is checked, then it will proceed to the checkout page. If not, it will show an alert box with the message &#8220;Please agree to the Terms and Conditions&#8221;, and the user will NOT be taken to the checkout page.</p>

<p>If you are using another Javascript framework such as Prototype in your theme, you may have to use noConflict mode. Shown below is the same code but in noConflict mode.</p>

<pre>
<code>&lt;script type="text/javascript"&gt;
 jQuery.noConflict();    
 jQuery(document).ready(function(){
   jQuery("#checkout").click(function(){
    if(jQuery('#agree').is(':checked')){
      jQuery("#checkout").submit();
    }
    else{
      alert("Please agree to the Terms and Conditions");
      return false;
   }
   });
 });
&lt;/script&gt;</code>
</pre>

<p>Once this code is in place, your customers will not be able to proceed to the checkout without having checked the &#8220;I agree&#8221; checkbox. If they don&#8217;t have it checked, they will be shown a Javascript alert box instead of being taken to the checkout page.</p>

<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/11/Screen-shot-2009-11-09-at-9.59.47-AM-612x485.png" alt="Screen shot 2009-11-09 at 9.59.47 AM" title="Screen shot 2009-11-09 at 9.59.47 AM" width="588" height="465" class="alignnone size-medium wp-image-612" /></p>

 <h2 class="steps">Conclusion</h2>

<p>This may be a bit bothersome from a buyer&#8217;s point-of-view, but from my understanding some places have laws that make it imperative to have an &#8220;I agree&#8221; checkbox when buying products online. You can download my example theme with the code in action <a href="http://blog.tetsutakara.com/wp-content/uploads/2009/11/tetsublog-checkout.zip">here</a>.</p>

<p>Hope that helped, &#8217;til next time!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tetsutakara.com/593/shopify-tutorial-making-sure-a-user-agrees-to-the-terms-conditions-using-jquery/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Shopify Tutorial: Customizing the Settings Form (Part 2 of 2)</title>
		<link>http://blog.tetsutakara.com/530/shopify-tutorial-customizing-the-settings-form-part-2-of-2/</link>
		<comments>http://blog.tetsutakara.com/530/shopify-tutorial-customizing-the-settings-form-part-2-of-2/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 00:05:44 +0000</pubDate>
		<dc:creator>Tetsuro</dc:creator>
				<category><![CDATA[Shopify]]></category>

		<guid isPermaLink="false">http://localhost:8888/?p=530</guid>
		<description><![CDATA[Last week I posted a tutorial on how to make some text customizable using the settings form. In this tutorial, I will be showing you how to customize the font and background using the settings form. I will be continuing to work on the Minimify theme that we modified in the last tutorial: please click [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I posted <a href="http://blog.tetsutakara.com/?p=248">a tutorial</a> on how to make some text customizable using the settings form. In this tutorial, I will be showing you how to customize the font and background using the settings form. I will be continuing to work on the Minimify theme that we modified in the last tutorial: please click <a href="http://blog.tetsutakara.com/wp-content/uploads/2009/09/minimify_mod.zip">here</a> to download the theme if you don&#8217;t have it handy.</p>

<h2 class="steps">1. Create a new fieldset</h2>

<p>Let&#8217;s start off by creating a new fieldset. Fieldsets allow you to group different sets of settings form inputs. For example, you can group all inputs that affect the font colors under a fieldset called &#8220;Font Colors&#8221;. Open the settings form code, add a new fieldset (as shown below in red).</p>

<pre><code>&lt;h3&gt;My very own settings form!&lt;/h3&gt;
&lt;fieldset&gt;
    &lt;legend&gt;Colors&lt;/legend&gt;
    &lt;table&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="text_color"&gt;Regular text&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="text_color" name="text_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="link_color"&gt;Link Color&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="link_color" name="link_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="link_hover_color"&gt;Link Color Hover&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="link_hover_color" name="link_hover_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
&lt;/fieldset&gt;
<span style="color:red;">&lt;fieldset&gt;
    &lt;legend&gt;Font, Logo, Background&lt;/legend&gt;
    &lt;table&gt;
    &lt;/table&gt;
&lt;/fieldset&gt;</span></code></pre>
<span id="more-530"></span>

<p>The &lt;legend&gt; tag works as the title of the fieldset. I named the new fieldset &#8220;Font, Background, Logo&#8221; because I&#8217;ll be adding settings for these elements in this tutorial. Notice how in the screenshot below, the title that I had between the &lt;legend&gt; tag appears as the title of the fieldset on the actual form. Your form should now look like this:</p>

<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/forms1a1-588x186.png" alt="forms1a" title="forms1a" width="588" height="186" class="alignnone size-medium wp-image-625" /></p>

<p>Alright! Now that we&#8217;ve got the new fieldset up, let&#8217;s fill&#8217;er up with some new settings!</p>

<h2 class="steps">2. Customizing the Regular Text Font</h2>

<p>To create a dropdown menu that will allow users to change font of the regular text, you must first insert a new &lt;select&gt; tag inside the fieldset. For the remainder of the tutorial, we&#8217;ll be working in this fieldset only. Open the code for settings.html, and enter the code colored in red below in our newly-created fieldset.</p>

<pre><code>&lt;fieldset&gt;
    &lt;legend&gt;Font, Logo, Background&lt;/legend&gt;
    &lt;table&gt;
      <span style="color:red;">&lt;tr&gt;
        &lt;th&gt;&lt;label for="regular_font"&gt;Regular text&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;
          &lt;select class="font" name="regular_font" id="regular_font"&gt;
               &lt;option value="Helvetica, Arial, sans-serif" selected="selected"&gt;Helvetica, Arial, sans-serif&lt;/option&gt;
          &lt;/select&gt;
        &lt;/td&gt;
      &lt;/tr&gt;</span>
    &lt;/table&gt;
&lt;/fieldset&gt;</code></pre>

<p>This will create a new drop-down with the id &#8220;regular_font&#8221; in your settings form. In my example, I have it so that &#8216;Helvetica, Arial, sans-serif&#8217; is the default font, but you can easily set it so that it&#8217;s another font from the list. For example, if you want Trebuchet MS to be the selected font, you can put the following &lt;option&gt; tag instead:</p>

<pre><code>&lt;option value="Trebuchet MS, sans-serif"&gt;Trebuchet MS, sans-serif&lt;/option&gt;</code></pre>

<p>Click save, and refresh your screen. Your settings form should now look like the screenshot below. </p>

<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/forms2a1-588x238.png" alt="forms2a" title="forms2a" width="588" height="238" class="alignnone size-medium wp-image-629" /></p>

<p>The next step is to link font selected in this new dropdown menu with layout.css.liquid. Open layout.css.liquid, and look for the &#8216;font-family&#8217; property for the body selector. The &#8216;body&#8217; selector for layout.css.liquid is shown below.</p>

<pre><code>body {
	background: #fff;
	padding: 0;
	margin: 0;
	font-family: Arial, Helvetica, sans-serif;
	line-height: 1.5em;
	font-size: small;
        color: {{ settings.text_color }};
	}</code></pre>

<p>You want to replace the value of the &#8216;font-family&#8217; property with the Liquid tag that outputs the option selected in the &#8220;regular_font&#8221; dropdown. To do this, simply replace the value for &#8216;font-family&#8217; with the following Liquid tag.</p>

<pre><code>font-family: {{ settings.regular_font }};</code></pre>

<p>Save layout.css.liquid. Now that the &#8220;regular_font&#8221; dropdown is tied in with layout.css.liquid, you can change the font on your site by simply selecting a font from the settings form, and clicking the &#8220;Save Changes&#8221; button!</p>

<h2 class="steps">3. Customizing the Logo</h2>

<p>Being able to swap logos is probably the most sought-after feature by those who do not know HTML/CSS. This can now be done very easily thanks to the settings form.</p>

<p>To start, enter the two new &lt;input&gt; tags (shown below in red and blue) inside the settings.html code.</p>

<pre><code>&lt;fieldset&gt;
    &lt;legend&gt;Font, Logo, Background&lt;/legend&gt;
    &lt;table&gt;
     &lt;tr&gt;
        &lt;th&gt;&lt;label for="regular_font"&gt;Regular text&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;
          &lt;select class="font" name="regular_font" id="regular_font"&gt;
            &lt;option value="Helvetica, Arial, sans-serif" selected="selected"&gt;Helvetica, Arial, sans-serif&lt;/option&gt;
          &lt;/select&gt;
        &lt;/td&gt;
     &lt;/tr&gt;
     <span style="color:red;">&lt;tr&gt;
       &lt;th&gt;&lt;label for="use_logo_image"&gt;Use a custom site logo?&lt;/label&gt;&lt;/th&gt;
       &lt;td&gt;&lt;input type="checkbox" id="use_logo_image" name="use_logo_image" value="1"/&gt;&lt;/td&gt;
     &lt;/tr&gt;</span>
     <span style="color:blue;">&lt;tr&gt;
      &lt;th&gt;Site logo&lt;/th&gt;
      &lt;td&gt;&lt;input type="file" id="logo_image" name="logo.png" data-max-height="200" data-max-width="800"/&gt;&lt;/td&gt;
     &lt;/tr&gt;</span>
    &lt;/table&gt;
&lt;/fieldset&gt;</code></pre>

<p>What&#8217;s really cool is that you can set the maximum width and maximum height of the logo being uploaded, using the &#8216;data-max-height&#8217; and &#8216;data-max-width&#8217; attributes. This means that you don&#8217;t have to worry about cropping your image to the right size, because the form will do it for you without screwing up the proportions of the image.  In the code above, I have set the maximum width to be 800 pixels because that is the width of the store&#8217;s layout.</p>

<p>Save the settings form, and hit refresh. Your settings form should now look like this:</p> 

<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/forms3a1-588x277.png" alt="forms3a" title="forms3a" width="588" height="277" class="alignnone size-medium wp-image-630" /></p>

<p>What we have now is a checkbox that checks to see if the user wants to use his own logo or not, and an input for selecting the image that the user wants to use as the logo. </p>

<p>Unlike the other settings, we need to modify theme.liquid instead of layout.css.liquid. This is because we&#8217;re going to be outputting an image, and not modifying a CSS property. Open up theme.liquid, and look for the div with id &#8220;header&#8221;. In the Minimify theme, this is the div that contains the logo, so we&#8217;re going to be adding some Liquid to link it with our settings form.</p>

<pre><code>&lt;div id="header" class="clearfix"&gt;
  &lt;h1 id="logo"&gt;
    &lt;a href="/" title="Go Home"&gt;{{shop.name}}&lt;/a&gt;
  &lt;/h1&gt;
  &lt;div id="cartlinks"&gt;
    &lt;h2 id="cartcount"&gt;
      &lt;a href="/cart"&gt;Cart&lt;/a&gt;&lt;sup&gt;{{ cart.item_count }}&lt;/sup&gt;
    &lt;/h2&gt;
  &lt;/div&gt;
&lt;/div&gt;</code></pre>

<p>Replace the &#8220;header&#8221; div with the code below.</p>

<pre><code>&lt;div id="header" class="clearfix"&gt;
  <span style="color:red;">{% if settings.use_logo_image %}</span>
    <span style="color:blue;">&lt;a href="/" title="Go Home"&gt;&lt;img src="{{ 'logo.png' | asset_url }}" alt="{{shop.name}}" /&gt;&lt;/a&gt;</span>
  <span style="color:red;">{% else %}</span>
  <span style="color:green;">&lt;h1 id="logo"&gt;
    &lt;a href="/" title="Go Home"&gt;{{shop.name}}&lt;/a&gt;
  &lt;/h1&gt;</span>
  <span style="color:red;">{% endif %}</span>
  &lt;div id="cartlinks"&gt;
    &lt;h2 id="cartcount"&gt;
      &lt;a href="/cart"&gt;Cart&lt;/a&gt;&lt;sup&gt;{{ cart.item_count }}&lt;/sup&gt;
    &lt;/h2&gt;
  &lt;/div&gt;
&lt;/div&gt;</code></pre>

<p>What we did above is we added a conditional statement (labeled above in red) to check to see if the user has the &#8220;use_logo_image&#8221; checkbox checked off. The line {% if settings.use_logo_image %} checks to see if &#8220;use_logo_image&#8221; is checked. If it is, then it will run the code in blue, which outputs &#8216;logo.png&#8217;. If it not checked, it will run the code shown above in green, which simply output the shop name in text.</p>

<p>When you upload an image for the logo, the form will automatically rename the file &#8220;logo.png&#8221;, so you don&#8217;t have to worry about renaming anything in theme.liquid.</p>

<p>
<strong>Before:</strong>
<img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/forms51-588x548.png" alt="forms5" title="forms5" width="588" height="548" class="alignnone size-medium wp-image-631" />
</p>

<p>
<strong>After:</strong>
<img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/forms4-588x549.png" alt="forms4" title="forms4" width="588" height="549" class="alignnone size-medium wp-image-634" />
</p>]]></content:encoded>
			<wfw:commentRss>http://blog.tetsutakara.com/530/shopify-tutorial-customizing-the-settings-form-part-2-of-2/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Shopify Tutorial: Customizing the Settings Form (Part 1 of 2)</title>
		<link>http://blog.tetsutakara.com/248/shopify-tutorial-customizing-the-settings-form-part-1-of-2/</link>
		<comments>http://blog.tetsutakara.com/248/shopify-tutorial-customizing-the-settings-form-part-1-of-2/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 13:22:40 +0000</pubDate>
		<dc:creator>Tetsuro</dc:creator>
				<category><![CDATA[Shopify]]></category>

		<guid isPermaLink="false">http://blog.tetsutakara.com/?p=232</guid>
		<description><![CDATA[A few weeks back, Shopify released a new feature that allows designers to create a form within the theme editor that allow those without programming knowledge to customize their theme. The default themes already come with a form that allows you to customize certain aspects of the theme, but what if you want to add [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks back, Shopify <a href="http://blog.shopify.com/2009/8/26/theme-customization-for-everyone" target="_blank">released a new feature</a> that allows designers to create a form within the theme editor that allow those without programming knowledge to customize their theme. The default themes already come with a form that allows you to customize certain aspects of the theme, but what if you want to add more customizable elements to the store? Or perhaps you&#8217;ve made a theme from scratch, and want to make your theme customizable so that your client can customize the theme themselves when you hand it over to them.</p>
<p>In this tutorial, I&#8217;m going to be using an older version of the Minimify theme to walk you through how to make the text colors customizable using the settings form. Please click <a href="http://blog.tetsutakara.com/wp-content/uploads/2009/09/minimify.zip">here</a> to download the Minimify theme. With that said, you can still follow this tutorial with a completely different theme.</p>
<h2 class="steps">1. Create the form</h2>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/settings11-588x125.png" alt="settings1" title="settings1" width="588" height="125" class="alignnone size-medium wp-image-640" /></p>
<p>In the Theme Editor, click the &#8220;Create a settings form&#8221; button.</p>
<p><span id="more-248"></span></p>
<h2 class="steps">2. Rename &#8220;layout.css&#8221; to &#8220;layout.css.liquid&#8221;</h2>
<p>The next thing you want to do is rename your CSS file so that it has a .liquid extension.  This will allow you to have Liquid variables in your CSS file, which is necessary in order to make the settings form affect the values in your CSS file.</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/settings21-588x271.png" alt="settings2" title="settings2" width="588" height="271" class="alignnone size-medium wp-image-641" /></p>
<p>Open layout.css, and click the &#8220;Rename&#8221; link up top. This will open a textbox where you can rename the file. Add &#8216;.liquid&#8217; to the name of the css file, and click the &#8220;Rename&#8221; button to save your changes.</p>
<h2 class="steps">3. Customizing the Regular Text Color</h2>
<p>Let&#8217;s start off by having the form modify the color of the regular text of the theme. By default, the form will have 5 customizable elements, Regular Text, Accents, Background, Headers, and Regular Text. Changing the values in the form won&#8217;t do anything yet, because we haven&#8217;t told  the layout.css.liquid file what to change.</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/settings31-588x221.png" alt="settings3" title="settings3" width="588" height="221" class="alignnone size-medium wp-image-642" /></p>
<p>In the theme editor, click the link that says &#8220;edit this form&#8221;. Doing this will open the code for settings.html.</p>
<p>Delete the entire content of settings.html, and copy/paste the following block of code. This is so that we can start fresh.</p>
<p>
<pre><code>  &lt;h3&gt;My very own settings form!&lt;/h3&gt;

  &lt;fieldset&gt;
    &lt;legend&gt;Colors&lt;/legend&gt;
    &lt;table&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="text_color"&gt;Regular text&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="text_color" name="text_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/fieldset&gt;</code></pre>
</p>
<p>Click save, close settings.html, and refresh your page. What you have now is a single color picker with the id &#8220;text_color&#8221;. This id is important to remember, as we need it to match it up with the color value in layout.css.liquid for the magic to happen. Your form should now look like this:</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/settings41-588x163.png" alt="settings4" title="settings4" width="588" height="163" class="alignnone size-medium wp-image-643" /></p>
<p>You can change the default color of the color picker by changing the hex value in the &#8220;value&#8221; attribute of the input. In the example above, it has the color &#8220;#d60f0f&#8221;, but you can change it to any hex color you wish.</p>
<p>Open layout.css.liquid, and look for the selector for the &#8216;body&#8217; attribute. It should look like this:</p>
<p>
<pre><code>  body {
    background: #fff;
    padding: 0;
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5em;
    font-size: small;
    <span style="color:red">color: #000;</span>
  }</code></pre>
</p>
<p>Notice the line in red &#8211; this is the CSS property that we want to modify with the form. What we&#8217;re going to do now is put in some Liquid to &#8216;link&#8217; the color value from the color picker to the value of the &#8220;color&#8221; property of the body selector.</p>
<p>Enter {{ settings.text_color }} for the value of the color property. It should look like this:</p>
<p>
<pre><code>  color: {{ settings.text_color }};</code></pre>
</p>
<p>Notice how &#8220;text_color&#8221; in the Liquid tag above matches up with the id of the color picker&#8217;s id. This is how we tell Liquid to take the hex value of the color picker with the id &#8220;text_color&#8221;, and output it in the CSS file. Save layout.css.liquid.</p>
<p>Here comes the exciting part! In your settings form, pick any color that you want to be the color for the regular text. Click the &#8220;Save changes&#8221; button. When you refresh your store, you should see that the regular text is now the color that you just chose in the Settings form!</p>
<h2 class="steps">Customizing the Link Colors</h2>
<p>Link colors are changed much in the same way as the regular text. Let&#8217;s start off by first adding two more color pickers to your form, one for link colors, the other for the hover color for links.</p>
<p>
<pre><code>  &lt;h3&gt;My very own settings form!&lt;/h3&gt;
  &lt;fieldset&gt;
    &lt;legend&gt;Colors&lt;/legend&gt;
    &lt;table&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="text_color"&gt;Regular text&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="text_color" name="text_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="link_color"&gt;Link Color&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="link_color" name="link_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;th&gt;&lt;label for="link_hover_color"&gt;Link Hover Color&lt;/label&gt;&lt;/th&gt;
        &lt;td&gt;&lt;input id="link_hover_color" name="link_hover_color" class="color" value="#d60f0f"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
  &lt;/fieldset&gt;</code></pre>
</p>
<p>Open the editor for settings.html by clicking &#8220;edit this form&#8221;. Enter in two more &#60;tr&#62; elements, one for each new color picker. Rename the attributes for the labels and inputs accordingly (I named mine &#8216;link_color&#8217; and &#8216;link_hover_color&#8217;). Your settings.html should now look like this:</p>
<p><img src="http://blog.tetsutakara.com/wp-content/uploads/2009/09/settings51-588x181.png" alt="settings5" title="settings5" width="588" height="181" class="alignnone size-medium wp-image-644" /></p>
<p>Open layout.css.liquid. Enter {{ settings.link_color }} and {{ settings.link_color_hover }} for the &#8216;a&#8217; and &#8216;a:hover&#8217; selectors, respectively, as follows:</p>
<p>
<pre><code> a {
	text-decoration: underline;
	<span style="color:red">color: {{ settings.link_color }};</span>
}

a:hover {
	<span style="color:red">color: {{ settings.link_hover_color }};</span>
	text-decoration: none;
}</code></pre>
</p>
<p>Now using your settings form, pick a color for the Link Color and Link Hover Color, and hit save changes. When you refresh your store, the links should be the color that you picked for Link Color, and when you hover over them, they should be the color that you picked for Link Hover Color!</p>
<h2 class="steps">Conclusion</h2>
<p>In this tutorial, I went over how to set up the settings form to change the colors of some of the text in your theme. You can download what we&#8217;ve done so far <a href="http://blog.tetsutakara.com/wp-content/uploads/2009/09/minimify_mod.zip">here</a>.</p>
<p>In part 2 of this tutorial, I will be walking through how to modify fonts and background images using the settings form. Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tetsutakara.com/248/shopify-tutorial-customizing-the-settings-form-part-1-of-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Shopify Tutorial: Conditional Statements in Liquid and Metadata</title>
		<link>http://blog.tetsutakara.com/171/shopify-tutorial-conditional-statements-in-liquid-and-metadata/</link>
		<comments>http://blog.tetsutakara.com/171/shopify-tutorial-conditional-statements-in-liquid-and-metadata/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 15:42:14 +0000</pubDate>
		<dc:creator>Tetsuro</dc:creator>
				<category><![CDATA[Shopify]]></category>

		<guid isPermaLink="false">http://blog.tetsutakara.com/?p=171</guid>
		<description><![CDATA[One question I see often in Shopify is “how do I make my metadata for the different pages on my store?”. I’m not sure how this affects ranking in search engines (in fact if anyone can clarify this for me, that would be awesome), but in this tutorial I will just show you how this [...]]]></description>
			<content:encoded><![CDATA[<p>One question I see often in Shopify is “how do I make my metadata for the different pages on my store?”. I’m not sure how this affects ranking in search engines (in fact if anyone can clarify this for me, that would be awesome), but in this tutorial I will just show you how this is done. This tutorial will also serve as a refresher on how to use conditional statements with Liquid.</p>
<h2 class="steps">A Brief Overview of Conditional Statements in Liquid</h2>
<p>Conditional statements are ways to tell Liquid (or any other programming language) to do something based on certain conditions. For example, you can tell the code &#8220;If  condition A is true, take action A. If condition B is true, take action B. If neither are true, take action C&#8221;. Below is an example of a conditional statement in Liquid:</p>
<pre><code>{% if template == "index" %}
       <span style="color:red">You are on the index page!</span>
{% elsif template == "collection" %}
       <span style="color:green">You are on the collection page!</span>
{% else %}
       <span style="color:blue">You are on a page that is NOT the index page nor the collection page!</span>
{% endif %}</code></pre>
<p>The code above will output the line in red if the visitor is on the index page of the Shopify store. Conversely, it will output the line in green if the visitor is on the collection page of the Shopify store. If the visitor is on a page that is not the index page nor the collection page, it will output the line in blue.</p>
<p><span id="more-171"></span></p>
<p>You can also have conditional statements within conditional statements. For example:</p>
<pre><code><span style="color:red">{% if template == "page" %}</span>
       <span style="color:green">{% if page.handle == "about-us" %}</span>
              You are looking at the About Us page!
       <span style="color:green">{% endif %}</span>
<span style="color:red">{% endif %}</span></code></pre>
<p>The code above will first run the conditional statement marked in red, which checks if the Liquid template that is currently being used is &#8220;page&#8221;. If it is, it will go to the next conditional statement below, marked in green. If not, it will go the end of the conditional statement, which will result in nothing being done.</p>
<p>The conditional statement marked in green checks to see if the handle of the page is equal to &#8220;about-us&#8221;. If it is, it will output the line  &#8220;You are looking at the About Us page!&#8221;. If the handle of the page does not equal &#8220;about-us&#8221;, it will not do anything.</p>
<p>By using a combination of if and elsif statements, as well as nested conditional statements, you can set up different metadata for every template or even for every different product, page, or collection that you may have.</p>
<h2 class="steps">1. Open theme.liquid</h2>
<p>If you are editing directly through the Shopify admin, theme.liquid is accessed by going to Assets &gt; Theme Editor, and clicking on the thumbnail that has the label &#8220;theme.liquid&#8221;.</p>
<p>If you are editing offline with Vision, open &#8220;theme.liquid&#8221; in the layout folder of your theme.</p>
<h2 class="steps">2. Add the Conditional Statements</h2>
<p>The head section of your theme.liquid should look something like the code below. It may not look exactly the same because you may have extra Javascript or CSS files, but what&#8217;s important here is that the if-statement goes under the &#8220;Content-Type&#8221; meta tag.</p>
<p>A Shopify theme can have up to 9 templates: article, blog, cart, collection, index, page, product, 404, and search. Each template corresponds to a specific section of a site &#8211; for example, &#8220;index&#8221; is the template used the first page of your Shopify store, and &#8220;product&#8221; is the template used for when you&#8217;re viewing a single product. In this example, we will be using 4 of the 9 available templates: index, page, product, and collection.</p>
<pre><code>{% if  template == "index" %}
      Index metadata goes here.
{% elsif template == "collection" %}
      Collection metadata goes here.
{% elsif template == "product" %}
      Product metadata goes here.
{% elsif template == "page" %}
      Page metadata goes here.
{% endif %}

{{ 'main.css' | asset_url | stylesheet_tag }}
{{ 'option_selection.js' | shopify_asset_url | script_tag }}
{{ content_for_header }}</code></pre>
<p>In the code above, I am checking to see which of the four templates the visitor is currently seeing: index, collection, product, or page. Once this is done, you can enter in more conditional statements to set up metadata for specific pages, collections, or products.</p>
<pre><code><span style="color:red">{% if  template == "index" %}</span>
      Index metadata goes here.
<span style="color:red">{% elsif template == "collection" %}</span>
      <span style="color:green">{% if collection.handle == "all" %}</span>
             Enter in metadata for 'all' collection here.
      <span style="color:green">{% elsif collection.handle == "summer" %}</span>
             Enter in metadata for 'summer' collection here.
      <span style="color:green">{% endif %}</span>
<span style="color:red">{% elsif template == "product" %}</span>
      <span style="color:blue">{% if product.handle == "t-shirt" %}</span>
             Enter in metadata for 't-shirt' product here.
      <span style="color:blue">{% elsif product.handle == "baseball-hat" %}</span>
             Enter in metadata for 'baseball-hat' product here.
      <span style="color:blue">{% endif %}</span>
<span style="color:red">{% elsif template == "page" %}</span>
      <span style="color:purple">{% if page.handle == "about-us" %}</span>
             Enter in metadata for 'about-us' page here.
      <span style="color:purple">{% elsif page.handle == "contact-us" %}</span>
             Enter in metadata for 'contact-us' page here.
      <span style="color:purple">{% endif %}</span>
<span style="color:red">{% else %}</span>
      Enter in default metadata in case none of the above conditions are met.
<span style="color:red">{% endif %}</span></code></pre>
<p>Using the format above, you can enter in different metadata descriptions and keywords for every different template, product, page, or collection. In this example, I only put two elsifs for each code block, but you can add as many elsif statements as you desire. Please click <a href="http://blog.tetsutakara.com/wp-content/uploads/2009/09/example_head.txt">here</a> to see an example of what the head section of your theme.liquid might look like.</ol>
<h2 class="steps">Conclusion</h2>
<p>As you can see, conditional statements can give you a lot of control over what is outputted on a page, and metadata is just one of many of its applications. In a future tutorial, I would like to go through how to accomplish the same thing with Liquid&#8217;s switch statements.</p>
<p><strong>UPDATE 09/23/2009:</strong></p>
<p>You can pretty much forget about using meta keywords for your sites &#8211; as explained by Google <a href="http://googlewebmastercentral.blogspot.com/2009/09/google-does-not-use-keywords-meta-tag.html" target="_blank">here</a>. You should still use meta description though!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.tetsutakara.com/171/shopify-tutorial-conditional-statements-in-liquid-and-metadata/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
