diff --git a/_basics/handle.md b/_basics/handle.md new file mode 100644 index 0000000..55e0e63 --- /dev/null +++ b/_basics/handle.md @@ -0,0 +1,96 @@ +--- +title: Handles +--- + +# Handles + + + + + + +## What is a handle + +The handle is used to access the attributes of a Liquid object. By default, it is the object's title in lowercase with any spaces and special characters replaced by hyphens (-). Every object in Liquid (product, collection, blog, link list) has a handle. + +For example, a page with the title "About Us" can be accessed in Liquid via its handle about-us as shown below: + +{% highlight html %}{% raw %} + +{{ pages.about-us.content }} +{% endraw %}{% endhighlight %} + +## How are my handles created? + +A product with the title "Shirt" will automatically be given the handle **shirt**. If there is already a product with the handle "Shirt", the handle will auto-increment. In other words, all "Shirt" products created after the first one will receive the handle **shirt-1**, **shirt-2**, and so on. + +{{ '/themes/handle-2.jpg' | image }} + +Whitespaces in a title are replaced by hyphens in the handle. For example, the title "*My Shiny New Title*" will result in a handle called **my-shiny-new-title**. + +{{ '/themes/handle-3.jpg' | image }} + +The handle will also determine the URL of that object. For example, a page with the handle "about-us" would have the url: [http://yourshop.myshopify.com/pages/about-us](http://yourshop.myshopify.com/pages/about-us) + +Shop designs often rely on a static handle for a page, product, or linklist. In order to preserve design elements and avoid broken links, if you modify the title of an object, **Shopify will not automatically update the handle.** + +For example, if you were to change your page title from "About Us" to "About Shopify" ... + +{{ '/themes/handle-4.jpg' | image }} + +... your handle will still be **about-us**. + +{{ '/themes/handle-5.jpg' | image }} + +However, you can change an object's handle manually by changing the value for the "URL & Handle" text box. + +{{ '/themes/handle-6.jpg' | image }} + + + +## Accessing attributes via the handle", "attributes-handle + + +In many cases you may know the handle of a object whose attributes you want to access. You can access its attributes by pluralizing the name of the object, then using either the square bracket ( [ ] ) or dot ( . ) notation. + +
Input
+Output
+pages as opposed to page.
+
+You can also pass in Customize theme page objects using this notation. This is handy for theme designers who wish to give the users of their themes the ability to select which content to display in their theme.
+
+Input
+Output
+== |
+ equals | +
!= |
+ does not equal | +
> |
+ greater than | +
< |
+ less than | +
>= |
+ greater than or equal to | + +
<= |
+ less than or equal to | +
or |
+ condition A or condition B | +
and |
+ condition A and condition B | +
contains checks for the presence of a substring inside a string.
+
+
+{% highlight html %}{% raw %}
+{% if product.title contains 'Pack' %}
+ This product's title contains the word Pack.
+{% endif %}
+{% endraw %}{% endhighlight %}
+
+
+contains can also check for the presence of a string in an array of strings.
+
+{% highlight html %}{% raw %}
+{% if product.tags contains 'Hello' %}
+ This product has been tagged with 'Hello'.
+{% endif %}
+{% endraw %}{% endhighlight %}
+
+
+You **cannot** check for the presence of an object in an array of objects using contains. This will not work:
+
+{% highlight html %}{% raw %}
+{% if product.collections contains 'Sale' %}
+ One of the collections this product belongs to is the Sale collection.
+{% endif %}
+{% endraw %}{% endhighlight %}
+
+This will work:
+
+{% highlight html %}{% raw %}
+{% assign in_sale_collection = false %}
+{% for collection in product.collections %}
+ {% if in_sale_collection == false and collection.title == 'Sale' %}
+ {% assign in_sale_collection = true %}
+ {% endif %}
+{% endfor %}
+{% if in_sale_collection %}
+ One of the collections this product belongs to is the Sale collection.
+{% endif %}
+{% endraw %}{% endhighlight %}
+
+
\ No newline at end of file
diff --git a/_basics/temp-index.md b/_basics/temp-index.md
new file mode 100644
index 0000000..ae46193
--- /dev/null
+++ b/_basics/temp-index.md
@@ -0,0 +1,40 @@
+---
+title: Basics
+---
+
+
+# Introduction
+
+Liquid is an open-source, Ruby-based template language created by Shopify. It is the backbone of Shopify themes and is used to load dynamic content on storefronts.
+
+
+
+Liquid uses a combination of _tags_, _objects_, and _filters_ to load dynamic content. They are used inside Liquid _template files_, which are a group of files that make up a theme. For more information on the available templates, please see Theme Development.
+
+## Tags
+
+Tags make up the programming logic that tells templates what to do.
+
+{% raw %}
+{% if user.name == 'elvis' %}
+ Hey Elvis
+{% endif %}
+{% endraw %}
+
+
+
+
+
+
+
+
+## Filters
+
+Filters are used to modify the output of strings, numbers, variables, and objects.
+
+{% raw %}
+{{ 'sales' | append: '.jpg' }}
+{% endraw %}
++Read more › +
\ No newline at end of file diff --git a/_basics/true-and-false.md b/_basics/true-and-false.md new file mode 100644 index 0000000..a3ef1d5 --- /dev/null +++ b/_basics/true-and-false.md @@ -0,0 +1,121 @@ +--- +title: Truthy and Falsy +--- + +# Truthy and Falsy in Liquid + + + +In programming, we describe “truthy” and “falsy” as anything that returns true or false, respectively, when used inside an if statement. + +## What is truthy? + +All values in Liquid are truthy, with the exception of nil and false. + +In the example below, the text “Tobi” is not a boolean, but it is truthy in a conditional: + +{% highlight html %}{% raw %} +{% assign tobi = 'Tobi' %} +{% if tobi %} +This will always be true. +{% endif %} +{% endraw %}{% endhighlight %} + +[Strings](/themes/liquid-documentation/basics/types/#strings), even when empty, are truthy. The example below will result in empty HTML tags ifsettings.fp_heading is empty:
+
+Input
+{% highlight html %}{% raw %} +{% if settings.fp_heading %} +Output
+{% highlight html %}{% raw %} + +{% endraw %}{% endhighlight %} + +To avoid this, you can check to see if the string isblank, as follows:
+
+settings.page is an empty string or set to a hidden or deleted object, you will end up with an EmptyDrop. The result is an undesirable empty <div>:
+
+Input
+{% highlight html %}{% raw %} +{% if pages[settings.page] %} +Output
+{% highlight html %}{% raw %} + +{% endraw %}{% endhighlight %} + + +## What is falsy? + +The only values that are falsy in Liquid are nil and false. + +[nil](/themes/liquid-documentation/basics/types/#nil) is returned when a Liquid object doesn't have anything to return. For example, if a collection doesn't have a collection image, collection.image will be set to nil. Since that is “falsy”, you can do this: + +{% highlight html %}{% raw %} +{% if collection.image %} + +{% endif %} +{% endraw %}{% endhighlight %} + +The value false is returned through many Liquid object properties such as product.available. + +## Summary + +The table below summarizes what is truthy or falsy in Liquid. + +| | truthy | falsy | +| ------------- |:-------------:|:-------------:| +| true | × | | +| false | | × | +| nil | | × | +| string | × | | +| empty string | × | | +| 0 | × | | +| 1 or 2 or 3.14 | × | | +| array | × | | +| empty array | × | | +| collection | × | | +| collection with no products | × | | +| page | × | | +| EmptyDrop | × | | + + + + + + + + + + + + + + + + + + + + + + diff --git a/_basics/types.md b/_basics/types.md new file mode 100644 index 0000000..4713b91 --- /dev/null +++ b/_basics/types.md @@ -0,0 +1,204 @@ +--- +title: Types +--- + +# Types + +Liquid objects can return one of six types: String, Number, Boolean, Nil, Array, or EmptyDrop. Liquid variables can be initialized by using the assign or capture tags. + + + +## Strings + +Strings are declared by wrapping the variable's value in single or double quotes. + +Input
+ +{% highlight html %}{% raw %} +Tracking number: {{ fulfillment.tracking_numbers }} +{% endraw %}{% endhighlight %} + +Output
+ +Input
+Output
+Input
+Output
+split filter to break a single string into an array of substrings. See here for examples.
+
+
+
+
+
+
+
+## EmptyDrop
+
+An EmptyDrop object is returned whenever you try to access a non-existent object (for example, a collection, page or blog that was deleted or hidden) by [handle](/themes/liquid-documentation/basics/handle). In the example below, page_1, page_2 and page_3 are all EmptyDrop objects.
+
+{% highlight html %}{% raw %}
+{% assign variable = "hello" %}
+{% assign page_1 = pages[variable] %}
+{% assign page_2 = pages["i-do-not-exist-in-your-store"] %}
+{% assign page_3 = pages.this-handle-does-not-belong-to-any-page %}
+{% endraw %}{% endhighlight %}
+
+EmptyDrop objects only have one attribute, empty?, which is always true.
+
+Collections and pages that _do_ exist do not have an empty? attribute. Their empty? is “falsy”, which means that calling it inside an if statement will return false. When using an unless statement on existing collections and pages, empty? will return true.
+
+#### Applications in themes
+
+Using the empty? attribute, you can check to see if a page exists or not _before_ accessing any of its other attributes.
+
+{% highlight html %}{% raw %}
+{% unless pages.frontpage.empty? %}
+
+ We do have a 'frontpage' collection but it's empty.
+ {% endfor %} +{% endunless %} +{% endraw %}{% endhighlight %} + + + + + + + diff --git a/_config.yml b/_config.yml index d42a8a7..0c56828 100644 --- a/_config.yml +++ b/_config.yml @@ -4,6 +4,8 @@ url: "http://liquidmarkup.org" # the base hostname & protocol for your site markdown: kramdown permalink: /:year/:month/:day/:basename:output_ext collections: + basics: + output: true filters: output: true tags: @@ -13,9 +15,3 @@ exclude: - CNAME - node_modules keep_files: ['css'] -defaults: - - - scope: - path: "" - values: - layout: "default" diff --git a/basics/index.html b/basics/index.html new file mode 100644 index 0000000..bd04fd4 --- /dev/null +++ b/basics/index.html @@ -0,0 +1,12 @@ +--- +layout: default +--- + +{% for doc in site.collections["basics"].docs %} +