Assign a random element from an array.

13 views
Skip to first unread message

Nash

unread,
Aug 7, 2008, 11:11:53 AM8/7/08
to Liquid Templates
Hi,

I need to do something like: {% assign foo = some_array | rand %},
but this doesn't work.

How can I have foo contain a random element from some_array?

Thanks.


-Nash

Tobias Lütke

unread,
Aug 7, 2008, 11:58:31 AM8/7/08
to liquid-t...@googlegroups.com
You would probably have to write your own {% assign_random %} tag

--
Tobi
http://shopify.com - modern e-commerce software
http://typo.leetsoft.com - Open source weblog engine
http://blog.leetsoft.com - Technical weblog

Daniel

unread,
Aug 7, 2008, 2:24:54 PM8/7/08
to Liquid Templates
sounds cool, how do you write your own tags? any tutorials out there
on that?

On Aug 7, 8:58 am, "Tobias Lütke" <tobias.lue...@gmail.com> wrote:
> You would probably have to write your own {% assign_random %} tag
>

Nash

unread,
Aug 9, 2008, 12:59:01 PM8/9/08
to Liquid Templates
Hi Tobi,

Is this the syntax you had in mind: {% assign_random foo =
some_array %} ?

I'm thinking have {% assign_random %} return a random element from
the array, but if some_array is not actually an array, it would behave
just like {% assign %}

Thanks.


-Nash

On Aug 7, 10:58 am, "Tobias Lütke" <tobias.lue...@gmail.com> wrote:
> You would probably have to write your own {% assign_random %} tag
>
> On Thu, Aug 7, 2008 at 11:11 AM, Nash <nkabb...@gmail.com> wrote:
>
> > Hi,
>
> >  I need to do something like:  {%  assign foo = some_array | rand %},
> > but this doesn't work.
>
> >  How can I have foo contain a random element from some_array?
>
> >  Thanks.
>
> > -Nash
>
> --
Reply all
Reply to author
Forward
0 new messages