Capture New Collection in VIEW in the Loop

38 views
Skip to first unread message

Breno Perucchi

unread,
Aug 31, 2012, 8:36:56 PM8/31/12
to liquid-t...@googlegroups.com
I need to capture new collection from the object that running in the loop.

I already try this, but don't return array. 

If @categories = ['1','2','3'] 

the new_collection has = "123"

---------------
VIEW
---------------
{% for cat in categories %}

--->  {% capture new_collection %} {{ cat.id | category_children:'1', }} {% endcapture %} <---

   {% for attr in new_collection %}
      <p> attr ID: {{ attr.id }} </p>
   {% endfor %}

{% endfor %}


------------------
LiquidFilter
------------------

  def category_children(id, depth = nil)
    if depth == nil
      @categories = Imentore::Category.find(id).descendants.collect{|category| Imentore::CategoryDrop.new(category)}
    else
      @categories = Imentore::Category.find(id).descendants(to_depth: depth.to_i)
    end
   @categories
  end

Reply all
Reply to author
Forward
0 new messages