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

I'm looking for a way to get an editable region that would show different content depending on the day (Monday, Tuesday, etc.)
Each day would be input in the admin and the page would select the input for the present day. The only thing i found was the calendar but i really just want a normal text region.

I am really bad at PHP coding and already tried searching in the forum for an answer. Can anyone please help?
If you have seven fields for your content named 'Sun_content', 'Mon_content', 'Tue_content' etc, then you can generate each day's field name with the cms:date tag, and then use cms:get to fetch the content of the field.
Code: Select all
<cms:set this_day="<cms:date format='D' />" />
<cms:set day_field="<cms:concat this_day '_content' />" />
<cms:get day_field />
@Silvercut,
@dmore54 code is perfect but in case it seems a little too terse for you, here is the simpler expanded version -

Code: Select all
<!-- date format with lowercase 'L' returns 'Sunday' through 'Saturday' -->
<cms:set this_day="<cms:date format='l' />" />

<cms:if this_day = 'Sunday' >
    <cms:show sunday_field />
</cms:if>

<cms:if this_day = 'Monday' >
    <cms:show monday_field />
</cms:if>

...
Worked like a charm!

To recap:

I've put the editable field in the template like this:

Code: Select all
<?php require_once( 'thecouchfolder/cms.php' ); ?>
<cms:template title='Accueil' order='1'>
<cms:editable name='monday_field' type='richtext'/>
<cms:editable name='tuesday_field' type='richtext'/>
<cms:editable name='wednesday_field' type='richtext'/>
<cms:editable name='thursday_field' type='richtext'/>
<cms:editable name='friday_field' type='richtext'/>
<cms:editable name='saturday_field' type='richtext'/>
<cms:editable name='sunday_field' type='richtext'/>
</cms:template>


And then the code from KK in the div where i want to display it:

Code: Select all
<div id="main_R_2_img">
              <!-- date format with lowercase 'L' returns 'Sunday' through 'Saturday' -->
            <cms:set this_day="<cms:date format='l' />" />

            <cms:if this_day = 'Sunday' >
               <cms:show sunday_field />
            </cms:if>
            <cms:if this_day = 'Monday' >
               <cms:show monday_field />
            </cms:if>
            <cms:if this_day = 'Tuesday' >
               <cms:show tuesday_field />
            </cms:if>
            <cms:if this_day = 'Wednesday' >
               <cms:show wednesday_field />
            </cms:if>
            <cms:if this_day = 'Thursday' >
               <cms:show thursday_field />
            </cms:if>
            <cms:if this_day = 'Friday' >
               <cms:show friday_field />
            </cms:if>
            <cms:if this_day = 'Saturday' >
               <cms:show saturday_field />
            </cms:if>
</div>


Thanks to dmore54 and to KK for the quick answer. Couch CMS is such a pleasure to work with! :)
@Silvercut

I know it is a little late to post but thought of doing it.

The Code:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Daywise - Filter content from Editable' parent="_date_" clonable='1' >
   <cms:editable name='quote' label='Quote' type='richtext' order='2' />
</cms:template>
<!DOCTYPE html>
<html>
   <head>
      <title>Daywise Filter</title>
   </head>
   <body>
      <cms:pages masterpage=k_template_name order='asc'>
         <cms:set current_day="<cms:date format='l' />" />
         <cms:set day="<cms:show k_page_title />" />
         Current Day: <cms:show current_day /> <br />
         My Day: <cms:show day />
         <cms:if current_day eq day>
            <cms:show quote />      
         </cms:if>
      </cms:pages>
   </body>
</html>
<?php COUCH::invoke(); ?>


If you run the code,do the follwoing:
1. Un-publish the Default page
2. Make sure to create your Cloned Page Title as Sunday, Monday, ..., Saturday in any sequence you want.
3. Just visit the front end and it will pick up your System Day (if code is on local) or Server Day (if code is online).

Let me know, if you please, if this is useful.

@KK sir, Please let me know if this approach is fine or this should not be the way to do it!

Regards,
GenXCoders
Image
where innovation meets technology
@genxcoders

Thanks for the option but i fear it would interfere with other functionality of my page. The `editable by days of the week` section is in my index page and i have another editable field in this page that is used as an announcement banner. The banner is then called upon by the others pages using:

Code: Select all
<cms:get_custom_field 'nouvelles' masterpage='index.php' />


ps: Sorry for the exhaustive explanation but im a french speaking non-coders who learn on the go. :)
No issues...
As i had mentioned:
I know it is a little late to post but thought of doing it.


and after replies by @KK Sir and @dmore54 I knew the query was well answered.
But thanks for the gesture for reverting to my post.

Regards,
GenXCoders
Image
where innovation meets technology
7 posts Page 1 of 1