Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hi

Maybe the feature I need is already possible, but I'm new with CouchCMS, I don't already know all the possibilities.

I need to have a list of entries (title, date from, date to, description, maybe a picture). These entries will be displayed on a page as special offers of the week for a shop. But I want to display only the articles which are special offer now (date_from <= now && date_to >= now).

Is there a way to do it with existing features? Maybe with show_repeatable, but its variables are limited to k_count and k_total_records, we cannot add date variables I think.

Thanks for your help!
Blaise
Hi and welcome, Blaise :)

We can do what you want with both repeatable-regions as well as normal cloned-pages.

I suggest you go for the cloned-pages route as it'll handle any number of custom fields (and also any number of 'offers' that'll keep adding on with time).

Here is how we can do it -
Create a clonable template (say named 'offers.php') and, in addition to all the regions required to hold data about an offer, define the following two 'datetime' fields -
Code: Select all
<cms:template clonable='1' title='Offers'>
   ..

    <cms:editable type='datetime' name='date_from' label='Date from' default_time='@current' />
    <cms:editable type='datetime' name='date_to' label='Date from' default_time='@current' />

    ..
</cms:template>



The 'datetime' region is present in Couch but is not enabled by default.
You'll find info about enabling it here - viewtopic.php?p=12667#p12667


Now you can create every new offer as a simple cloned page of this template and set the start/end dates.

On the front-end, wherever you want to display the current offers, use the following code -
Code: Select all
<cms:set cur_date="<cms:date format='Y-m-d H:i:s' />" />

<cms:pages masterpage='offers.php' custom_field="date_from <= <cms:show cur_date /> | date_to >= <cms:show cur_date />">
    .. all variables of the offer pages available here ..
</cms:pages>

Hope this helps.
Do let us know.

Thanks
2 posts Page 1 of 1
cron