Files
liquid/_posts/objects/index.md
2014-07-23 11:17:11 -04:00

8.0 KiB
Raw Blame History

layout, title, landing_as_article, nav
layout title landing_as_article nav
default Objects true
group weight
Liquid Documentation 2

Objects

Liquid objects contain attributes to output dynamic content on the page. For example, the product object contains an attribute called title that can be used to output the title of a product.

Liquid objects are also often refered to as Liquid variables.

To output an object's attribute on the page, wrap them in {{ and }}, as shown below:

{% highlight html %}{% raw %} {{ product.title }} {% endraw %}{% endhighlight %}

Global Objects

The following objects can be used and accessed from any file in your theme, and are defined as global objects, or global variables:

blogs
{% highlight html %}{% raw %}
    {% for article in blogs.myblog.articles %}
  • {{ article.title | link_to: article.url }}
  • {% endfor %}
{% endraw %}{% endhighlight %}

The liquid object blogs refers to the blogs in your shop. More info

cart

The liquid object cart refers to the cart in your shop. More info

collections
{% highlight html %}{% raw %} {% for product in collections.frontpage.products %} {{ product.title }} {% endfor %} {% endraw %}{% endhighlight %}

The liquid object collections contains a list of all of the collections in a shop. More info

current_page
{% highlight html %}{% raw %} {% if current_page != 1 %} Page {{ current_page }}{% endif %} {% endraw %}{% endhighlight %}

The current_page object returns the number of the page you are on when browsing through paginated content. More info

current_tags
{% highlight html %}{% raw %} {% if current_tags %}

{{ blog.title | link_to: blog.url }} {{ current_tags.first }}

{% else %}

{{ blog.title }}

{% endif %} {% endraw %}{% endhighlight %}

The current_tags object will contain a different list of tags depending on the type of template that is rendered. More info

customer
{% highlight html %}{% raw %} {% if shop.customer_accounts_enabled %} {% if customer %} My Account {{ 'Log out' | customer_logout_link }} {% else %} {{ 'Log in' | customer_login_link }} {% if shop.customer_accounts_optional %} {{ 'Create an account' | customer_register_link }} {% endif %} {% endif %} {% endif %} {% endraw %}{% endhighlight %}

The liquid object customer is only defined when a customer is logged-in to the store. More info

linklists
{% highlight html %}{% raw %}
    {% for link in linklists.categories.links %}
  • {{ link.title | link_to: link.url }}
  • {% endfor %}
{% endraw %}{% endhighlight%}

The liquid object linklists contains a collection of all of the links in your shop. You can access a linklist by calling its handle on linklists. More info

pages
{% highlight html %}{% raw %}

{{ pages.about.title }}

{{ pages.about.author }} says...

{{ pages.about.content }}
{% endraw %}{% endhighlight %}

The liquid object pages refers to all of the pages in your shop. More info

page_description
{% highlight html %}{% raw %} {% if page_description %} {% endif %} {% endraw %}{% endhighlight %}

Merchants can specify a page_description. That field is automatically populated with the product/collection/article description. More info

page_title
{% highlight html %}{% raw %} {{ page_title }} {% endraw %}{% endhighlight %}

The liquid object page_title returns the title of the current page. More info

shop

The liquid object shop returns information about your shop. More info

template
{% highlight html %}{% raw %} {% if template contains 'product' %} WE ARE ON A PRODUCT PAGE. {% endif %} {% endraw %}{% endhighlight %}

The liquid object template returns the name of the template used to render the current page, with the .liquid extension omitted. As a best practice, it is recommended that you use the template object as a body class. More info

settings
{% highlight html %}{% raw %} {% if settings.use_logo %} {{ 'logo.png' | asset_url | img_tag: shop.name }} {% else %} {{ shop.name }} {% endif %} {% if settings.featured_collection and settings.featured_collection != '' and collections[settings.featured_collection].handle == settings.featured_collection and collections[settings.featured_collection].products_count > 0 %} {% for product in collections[settings.featured_collection].products %} {% include 'product-loop' %} {% endfor %} {% endif %} {% endraw %}{% endhighlight %}

The liquid object settings gives you access to all of the theme settings. More info

theme
{% highlight html %}{% raw %} Go to your theme settings. {% endraw %}{% endhighlight %}

The liquid object theme represents the currently active theme. More info

themes
{% highlight html %}{% raw %} We have a beautiful mobile theme, it's called {{ themes.mobile.name | link_to_theme: "mobile" }} {% endraw %}{% endhighlight %}

The liquid object themes provides access to the shop's published themes. More info