我今天花了试图为http://bitcoin.org/clients.html杰基尔随机排序集合
我们的Bitcoin软件的列表,做一些简单的与杰基尔,并每隔一段时间,该页面被再生。如果客户的订单会被随机分配以获得同等的曝光,那将是一件好事。
{% random page.clients %}
{% for client in page.clients %}
...
我敢肯定,这很简单:
class Random < Liquid::Tag
def initialize(tag_name, collection_name, tokens)
@collection_name = collection_name.to_s
super
end
def render(context)
collection = context[@collection_name]
collection = collection.sort_by{rand}
context[@collection_name] = collection
super
end
end
Liquid::Template.register_tag('random', Random)
为什么它不工作?我看到绝对没有变化。
我以为我不分配给正确page.clients,因为如果我尝试:
context[:foo] = collection
{% random page.clients %}
{% for client in page.clients %}
...
然后我得到一个空白页。但打印@collection_name显示“page.clients”...
任何想法?
感谢