I have a content type with field_1 and field_2. I want to have two blocks displaying different fields from a one random node. I can easily create two random blocks via views module, but they wil not be synchronized. Any ideas?

  • 1
    Why would you even need that? Can't you make it one block, and then style it to look like two, for example? – Mołot Jun 26 '15 at 9:11
  • I understand that there are many ways to achieve similar behaviour. But I'm curious :) – Oleksandr Berezko Jun 26 '15 at 12:17
  1. Define helper function like _random_node_id() which stores generated id in the static variable.
  2. Use this function as an argument in the view.

This function will return a random node id, but called twice on the same page it would return the same id (because it is static).

  • Won't work if one of the blocks will get loaded from cache from some reason. – Mołot Jun 26 '15 at 9:47
  • Assuming CACHE_PER_PAGE it should be ok. Tricky case => tricky solution J – tonystar Jun 26 '15 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.