How do you choose a media item at random from a Page Connection in a Zotonic template?

11 views
Skip to first unread message

Alain O'Dea

unread,
Oct 12, 2010, 12:47:20 PM10/12/10
to Zotonic users
Please answer on StackOverflow:
http://stackoverflow.com/questions/3917048/how-do-you-choose-a-media-item-at-random-from-a-page-connection-in-a-zotonic-temp

I would like to render a random connected media item in Zotonic as
follows:

{% with m.rsc[id].banner as media %}
{% if media %}
{% with media.random as m %}
{% media m %}
{% endwith %}
{% endif %}
{% endwith %}

How do you choose a media item at random from a Page Connection in a
Zotonic template?

Arjan Scherpenisse

unread,
Oct 12, 2010, 3:12:14 PM10/12/10
to zotoni...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Didn't try it, but:

{% with m.rsc[id].banner|random as randombanner %}

should work?

See http://zotonic.com/filter-random


Arjan


On 10/12/2010 06:47 PM, Alain O'Dea wrote:
> {% with m.rsc[id].banner as media %}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAky0sw4ACgkQigE4AbflYeoyewCgs53pWvzz9EEq/OfytqDSUTnN
+A8An2ZleomT21hxqXWnaey3fwpUGjH1
=bAV8
-----END PGP SIGNATURE-----

Alain O'Dea

unread,
Oct 12, 2010, 3:25:03 PM10/12/10
to Zotonic users
That didn't work, but it's a good starting point. Thank you Arjan.

I am going to debug the random filter and figure out why it doesn't
like my resource collection :)

On Oct 12, 5:12 pm, Arjan Scherpenisse <ar...@scherpenisse.net> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Didn't try it, but:
>
> {% with m.rsc[id].banner|random as randombanner %}
>
> should work?
>
> Seehttp://zotonic.com/filter-random
>
> Arjan
>
> On 10/12/2010 06:47 PM, Alain O'Dea wrote:> {% with m.rsc[id].banner as media %}
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org/

Marc Worrell

unread,
Oct 12, 2010, 5:03:48 PM10/12/10
to zotoni...@googlegroups.com
Try:

{% with m.rsc[id].banner|make_list|random as randombanner %}

The 'make_list' should be part of 'random', at least that would make life easier :-)

- Marc

Alain O'Dea

unread,
Oct 12, 2010, 7:49:18 PM10/12/10
to zotoni...@googlegroups.com
That works beautifully.  Thank you Marc.  There are free points for the taking on StackOverflow if you care for them.  My self-answered questions look a little weak :)
Reply all
Reply to author
Forward
0 new messages