Do you have some feature in mind that you'd love to see in Couch? Let us know.
6 posts Page 1 of 1
It would be nice to add random as a order-parameter for show_repeatable:
Code: Select all
<cms:show_repeatable 'random_images' order='random' limit='1'>
<img src="<cms:show image />" >
</cms:show_repeatable>
I added a pull request :)
Thanks :)
Have merged it.
Hi SimonWpt and KK,

Let us note that repeatable regions are one of the best things about Couch CMS. They solve all sorts of tasks and are used very often.
Sometimes the repeatable region only needs to display one item - for example, the administrator can load several banners, but only one of them is displayed at the front end at random. This is easily achievable -
Code: Select all
   <cms:show_repeatable 'banners'>
      <cms:if k_count="1" >
         <cms:set random_number="<cms:php>echo rand(1, <cms:show k_total_records />);</cms:php>" 'global' />
      </cms:if>
   
      <cms:if k_count="<cms:show random_number />" >
         <cms:show banner/>   
      </cms:if>
   </cms:show_repeatable>


But if you have to show a few elements at random then it's more complicated - the code gets big and heavy.
It would be really great if the repeatable region maintains order='random'.

I also ask KK to try to find a systemic solution.

Thanks
Hi @orbital,

Repeatable regions already support selecting only one (or a few of the rows) through 'limit' and 'offset' params - please see '3. Revised repeatable-regions' (viewtopic.php?f=5&t=11105).

@SimonWpt's addition (which has been merged with the core and you can get it from GitHub) adds the random part so you can now simply do -
Code: Select all
<cms:show_repeatable 'banners' limit='1' order='random'>
    <cms:show banner />
</cms:show_repeatable>

Hope this helps.
Thanks, this works great. I believe it will be useful for the huge number of Couch CMS users.
6 posts Page 1 of 1
cron