Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
I have this code which is limiting the results to 3 but I assumed if the start count is 0 then the first would be 0 and second 1 and third 2 which would mean the k_count should be 3? But if I set it to 3 then it shows 2 only. So I assume if I set start count at 0 it starts counting at 1?:

Code: Select all
               <div class="news">
                  <cms:pages masterpage='events.php' startcount='0'>
                     <cms:show_repeatable 'events'>
                        <cms:if k_count lt '4'>
                            <div class="col-md-4 new-more">
                              <div class="now-more1">
                                 <div class="event">
                                    <h4><cms:show date /></h4>
                                    <label></label>
                                    <h6><a href="single.html"><cms:show title /></a></h6>
                                    <p><cms:show description /></p>
                                    <a href="single.html" class="hvr-rectangle-out ">Learn More</a>
                                 </div>
                              </div>
                           </div>
                        </cms:if>
                        </cms:show_repeatable>
                  </cms:pages>
                  <div class="clearfix"> </div>
               </div>


I need to display only 3 entree's
I need to sort them by date, the date is a regular text field where they type October 15th, 2016

This is the events.php code in the top of the page:

Code: Select all
<?php require_once('manage/cms.php'); include('assets/config.php'); ?>
<cms:template title='Events' order='6' >

   <cms:repeatable name='events' >
       <cms:editable type='image' name='image' label='Photo' show_preview='1' preview_width='150' input_width='200' col_width='300' />
       <cms:editable type='text' name='title' label='Title' desc='Enter a title' />
       <cms:editable type='text' name='date' label='Date' desc='Enter a date' />
       <cms:editable type='textarea' name='description' label='Description' desc='Enter a description' />
   </cms:repeatable>

</cms:template>
<?php COUCH::invoke(); ?>


Is there a better way to do this? Using repeatable lets them "sort" the rows as they want them to appear. However I am just looking to show them from newest to oldest dates and only the first 3 results following those rules.

Thanks again!
First part of your question is about 2 different 'k_count's:

Code: Select all
<cms:pages masterpage='index.php' startcount='0' >

With this you assume, that you have *more than one* page in a clonable template. So you define start of counting (in this case it is '0'). But your template is not clonable.

Illustration of the first counter:
place cms:dump inside your cms:pages tag, like this:
Code: Select all
<cms:pages masterpage='events.php' startcount='0' >
    <cms:dump />
</cms:pages>

You will get output, which goes like
k_count: 0
k_total_records: 1

It means, that there is only one page and k_count can never be 1 or 2. Only stays '0'. It is the first counter in the scope of 'pages' tag.

However 'cms:repeatable' has its own counter. Now place cms:dump inside your repeatable:
Code: Select all
<cms:show_repeatable 'events'>
    <cms:dump />
</cms:show_repeatable>

I have 4 events in admin panel. Therefore output goes like:
*show_repeatable
image:
title: even title
date: 16 nov 2015
description: some description
k_count: 1
k_total_records: 4


So, even if you omit 'startcount' in 'pages' at all - it has no influence whatsoever on your repeatable. Please, let me know if this explanation is clear enough.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Since we have covered the k_count issue, let's get to the second part of your question.
I need to sort them by date, the date is a regular text field where they type October 15th, 2016

This one is not possible directly with repeatable. It has no options to manipulate data, though it is usually not needed (you mentioned that people input events in their preferable order).
Is there a better way to do this? Using repeatable lets them "sort" the rows as they want them to appear. However I am just looking to show them from newest to oldest dates and only the first 3 results following those rules.

I doubt that 'sorting' in repeatable region by manually replacing text values is a good solution in case there are many events. It is usually better to use clonable pages. Some ideas of the concept with working code can be borrowed from here http://docs.couchcms.com/concepts/events-calendar.html I guess, with clonables you can use a published date, which is selected with calendar toolbar in Advanced Menu, therefore no mistakes in date-entry could spoil your true sorting. If you prefer stick to repeatables for some reasons (which are completely understandable and viable too), then the above mentioned link has a text editable with validation for data entry and also can be very handy to make sure the date is entered without errors (extra/missed spaces, correct format, etc.).

That said, a sorting algo for a repeatable region can also be implemented with couch tags. But it will be so complex in my view, that it is better to avoid this solution completely in favor of native dates in clonable pages.
If you still need to sort simple text fields, then you'd need to require users enter months not in text format, but in digits. In other case it would be a hell of a task to sort them out.
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
Also links to consider:
Native datetime editable: viewtopic.php?p=12667#p12667
Compare date fields
viewtopic.php?f=2&t=6969
Event list with upcoming and past events
viewtopic.php?f=4&t=7255
Join COUCH:TALK channel here https://t.me/couchcms_chat
Ryazania — a framework to boost productivity with Add-ons viewtopic.php?f=2&t=13475
Support my efforts to help the community https://boosty.to/trendo/donate
4 posts Page 1 of 1