mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 15:30:39 -07:00
Slice filter for arrays.
This commit is contained in:
@@ -45,7 +45,12 @@ module Liquid
|
||||
def slice(input, offset, length=nil)
|
||||
offset = Integer(offset)
|
||||
length = length ? Integer(length) : 1
|
||||
input.to_s.slice(offset, length) || ''
|
||||
|
||||
if input.is_a?(Array)
|
||||
input.slice(offset, length) || []
|
||||
else
|
||||
input.to_s.slice(offset, length) || ''
|
||||
end
|
||||
end
|
||||
|
||||
# Truncate a string down to x characters
|
||||
|
||||
Reference in New Issue
Block a user