Coded something up in Couch in an interesting way? Have a snippet or shortcode to share? Post it here for the community to benefit.
49 posts Page 1 of 5
UPDATE: Beginning with v1.4RC, Couch ships with a native 'datetime' editable region that can be used as an alternative to the technique discussed in this thread. Full details of the region can be found here: viewtopic.php?p=12667#p12667

Original message:

To complement @cheesypoof's 'Colorpicker' (http://couchcms.com/forum/viewtopic.php?f=8&t=7124), here comes a 'Datepicker'.
Does not have a lot of features but helped me get by on at least one occasion (an events calender that needed an end date for each item).

Place the attached files into the 'couch' folder and then create the following two editable regions in any template that requires the datepicker
1. of type text that actually holds the date inputted.
2. of type 'message' that injects the JavaScript library that shows the calender popup to help in choosing a date.
Code: Select all
   <cms:editable name='end_date' 
      label='Event End Date (if multi-days event)'
      desc='Enter date in yyyy-mm-dd format e.g. 2010-12-31'
      type='text'
      validator='regex=/(?:19|20)\d\d-(?:0[1-9]|1[012])-(?:0[1-9]|[12][0-9]|3[01])/'
      separator='#'
      validator_msg='regex=Incorrect date format'
      width='155'
   />   
   
   <cms:editable name='datepicker' type='message'>
      <link rel="stylesheet" type="text/css" media="all" href="<cms:show k_admin_link />addons/datepicker/datepicker.css" />
      <script type="text/javascript" src="<cms:show k_admin_link />addons/datepicker/datepicker.js"></script>
      <script type="text/javascript">
         window.addEvent('domready',
            function(){
               $('f_end_date').addEvent('click', function(e){
               displayDatePicker('f_end_date');
               });
            }
         );
      </script>
   </cms:editable>

Please note that the name of the text region is 'end_date' while the datepicker is given 'f_end_date' (i.e. 'f_' appended)
$('f_end_date').addEvent('click', function(e){
displayDatePicker('f_end_date');
});

Attachments

Is there a way to change the date format?

Thanks,
Steve C
@judgearraow
This hack is really just a thin wrapper around the JavaScript contained in 'datepicker.js'. You can edit the original JavaScript to change the date format.

I must add though that, if you change the existing date format you won't be able to use the modified format as a parameter to Couch tags e.g. for limiting the pages fetched by cms:pages tag (Couch expects a date to be only in YYYY-MM-DD format).

If it is only for the purpose of displaying the date in a particular format on the front-end, you can safely use any format you wish.
This date picker might be really helpful..and I have a doubth ..can we display pages based on this dates? like not on the published date ..
For example : I have a editable event date.. which i enter them manually in admin panel while creating page..now i want to dispaly in a column like upcoming events which should be based on the dates i enter.. can i know is there a possiblity? will this date picker help me in this problem?
The cms:pages tag supports the use of any editable region to specify the pages it fetches.
We use the 'custom_field' parameter for doing so.

For example (as described in the docs http://www.couchcms.com/docs/tags-reference/pages.html), the following snippet will fetch only those pages that have the value 'jeffrey' anywhere in editable region named 'my_blog_author'
Code: Select all
<cms:pages masterpage='blog.php' custom_field='my_blog_author=jeffrey'>
..
</cms:pages>

Similarly we can also use the date field. For example if we have an editable region named 'my_date' that is used by the datepicker, the following snippet should fetch all pages that have a date falling in the month of November 2012
Code: Select all
<cms:pages masterpage='blog.php' custom_field='my_date>=2012-11-01 | my_date<2012-12-01'>
..
</cms:pages>

The code above simply fetches all pages that have a date greater than or equal to the first day of Nov 2012 AND smaller than the first day of Dec 2012.

I must add that although there will be scenarios when using the custom_field date as shown above will come in handy but, as much as possible, you should use the publish_date for all date related fetching.
This is because the publish_date is a native type and your code will definitely run more optimized using it. Additionally using the publish_date you can group pages according to dates (using cms:archive tag) - something that cannot be done using the custom_field method.
Hi.. KK that's what I'm looking for thanks for that..

but the problem with depending on publish dates is like our event date and publish date can't be on same date

<cms:pages masterpage='movie1.php' custom_field='end_date>=2012-10-01 | end_date<2012-10-01'>

I think in this, if the tag compares with our system date and display results that can be more flexible in comaprison ..

Like in displaying events.. we can display recent events happend and upcoming events by comparing the dates ..
..the problem with depending on publish dates is like our event date and publish date can't be on same date

Why not? The publish_date is simply 'prescriptive' - you can put it any use.
If you are concerned with the fact that the cms:pages tag does not fetch pages with publish_date falling in the future, this behaviour can be overridden by using the 'show_future_entries' parameter e.g.
Code: Select all
<cms:pages masterpage='events.php' show_future_entries='1'>
..
</cms:pages>

Please take a look at our documentation - http://www.couchcms.com/docs/concepts/e ... endar.html where we build an event calendar using this technique. If you search the forum you'll find threads discussing this in further detail.
Hi KK... I kept this as code in profile template to fetch related information

<cms:pages masterpage='works.php' custom_field='my_cast=k_page_title'>
<a href="<cms:show k_page_link />"> <cms:show k_page_title /></a><hr />
</cms:pages>

m not getting the results.. can't we compare the custom field value with the current page name? is there anythign wrong..I'm not getting the result
Try
Code: Select all
<cms:pages masterpage='works.php' custom_field="my_cast=<cms:show k_page_title />">
   <a href="<cms:show k_page_link />"> <cms:show k_page_title /></a><hr />
</cms:pages>

Does it help? Please let me know.
yup it worked... but now i kept the custom field in repeatable tags .. the error now is "my_cast" does not exist
49 posts Page 1 of 5

Who is online

In total there are 3 users online :: 1 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: Google [Bot] and 2 guests