Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
2 posts Page 1 of 1
Hello folks!
Some days ago it was needed to show on a page only X items from a "repeatable" region, and to make my day worse, all X items should start from position Y (for example to show 3 items from position 2, that should display items 2, 3 and 4). So I decided to mod a little bit the "repeatable" addon. This modded add-on introduces 2 new parameters:
startfrom which indicates index from which the rows will be displayed and
howmany which set the number of rows to be displayed.
A quick example will be like this:
Definition of repeatable region (nothing new here)
Code: Select all
<cms:repeatable name='test_repeat' label='Test'>
      <cms:editable type='text' name='value' label='Value' col_width='250' />
</cms:repeatable>

and the code used to display only 5 elements (using those 2 new tags)
Code: Select all
<cms:show_repeatable 'test_repeat' startfrom='3' howmany='5' >
      <cms:show value />
</cms:show_repeatable>

which will display only rows C, D, E, F, G - assuming you've have rows A to I already entered in admin.

To install this addon, simply replace the original /couchcms/addons/repeatable/repeatable.php with the one from archive attached to this post. Hoping you'll find it useful, please note I'm not a hardcore PHP coder, so if someone can make it better, feel free to do so.
P.S. I'm not native english speaker, but I hope I was clear enough about how to use this mod.

Attachments

Thanks so much Pandele!

Previously I had to use <cms:if k_count lt '3'></cms:if> within the repeatable region but this took forever when you had to go through 200 rows in the table. This newer technique is noticeably quicker and doesn't return so many blank lines in our HTML code output.
2 posts Page 1 of 1
cron