---
title: How to Emulate Liquid&#39;s Offset &amp; Limit Filters in Twig
author: George Mandis <george@mand.is>
date: 2014-12-17
description: A very quick and syntactically elegant way to element Liquid&#39;s offset filter in Twig.
tags: post, post, twig, liquid
---

When I work on [Shopify](http://www.shopify.com/?ref=snaptortoise) themes in Liquid I often rely on the `offset` and `limit` filters on `for` loops to achieve various goals. In lieu of an actual server-side environment to properly prep the data it generally works well enough for most things.

Today I was working on a project that uses Twig. It's similar to Jekyll in many ways — as is [Swig](/2014/02/chose-swig-jade-templates-nodeexpress-project/), which is probably why I like them both — but has a few differences here and there. One of those differences is the lack of these filters.

A quick Google search brought up [this old Google Groups discussion](https://groups.google.com/forum/#!topic/twig-users/pUhTbFn8TSk) along with the [general documentation on loops](http://twig.sensiolabs.org/doc/tags/for.html). In rereading the documentation regarding the [slice filter](http://twig.sensiolabs.org/doc/filters/slice.html) I realized you can emulate those filters quite elegantly!

To emulate Liquid's `offset` filter in Twig:

{% raw %}
    {% for item in group[1:] %}    
        {{ item.attribute }}   
    {% endfor %}
    

To emulate Liquid's `limit` filter in Twig:

    {% for item in group[:1] %}    
        {{ item.attribute }}
    {% endfor %}  

Obviously you can replace the number 1 in both examples with whatever you wish to offset or limit the group by.

Nice to know!

{% endraw %}