Couch 2.0+ offers great customization options for list-view. This is how I apply custom date to all templates.

In my experience with CouchCMS, I have developed a certain way to handle cms:template definitions. Below is a sample for my index.php template with smart_embed tag:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Index' clonable='1' dynamic_folders='1' order='0010'>
    <cms:smart_embed 'template_editables' />
</cms:template>


As stated in docs http://docs.couchcms.com/miscellaneous/smart_embed.html cms:smart_embed will look for a specified folder (in my case it is 'template_editables' ) in the /snippets folder. Next, it will automatically load a snippet from that folder with a specific name, with specific name selection dependent on current view. So, docs say that a snippet with a name "default" will load with any view, that is why I always have a snippet /snippets/template_editables/default.html with following content:

Code: Select all
<cms:config_list_view >

    <cms:if k_template_nested_pages = '1' >
       
        <cms:block 'config_list_view_inner' >
            <cms:field 'k_selector_checkbox' />
            <cms:field 'k_page_title' />
            <cms:field 'k_comments_count' />
            <cms:field 'k_up_down' />
            <cms:field 'k_actions' />
        </cms:block>   

    <cms:else_if k_template_is_clonable = '1' />   
       
        <cms:block 'config_list_view_inner' >
            <cms:field 'k_selector_checkbox' />
            <cms:field 'k_page_title' />
            <cms:field 'k_comments_count' />
            <cms:field 'k_page_foldertitle' />
            <cms:field 'k_page_date' />
            <cms:field 'k_actions' />
        </cms:block>

    </cms:if>

</cms:config_list_view>


<cms:block 'editables' />



So, by having 'default.html' and using cms:smart_embed in all templates within cms:template block, I manage to have the code above load for all templates.

In almost every template in real life, cms:template block also holds editable definitions. So again cms:smart_embed helps with that. For index.php I place a snippet named "index-default.html" and define custom editables there. Complete sample of this snippet:

Code: Select all
<cms:extends 'template_editables/default.html' />

<cms:block 'editables'>

        <cms:editable name='post' label='Content' type='textarea' />
   
</cms:block>


Now, the best outcome of the above configuration is that I can apply customizations to all templates by changing a certain block or adding a new one (more info about cms:block in Template Inheritance post viewtopic.php?f=5&t=10984 ). For all templates I can define some editable as well, or maybe output custom message with cms:html etc..

To mod k_publish_date for all templates I can simply change default definition from
<cms:field 'k_page_date' />
to
<cms:field 'k_page_date' ><cms:date k_page_date format='d.m.Y' /></cms:field>
and that's it - it will be loaded for all templates from 'default.html' snippet.

However, for one template I want to have a different look of the k_page_date column in list-view. So I will add a block in 'default.html' and apply a different configuration in a specific template snippet. Such template is my extended_users template, which needs to display date with header 'Activated' and new format.

default.html config_list_view now becomes as follows (adding a cms:block to k_page_date)
Code: Select all
        <cms:block 'config_list_view_inner' >
            <cms:field 'k_selector_checkbox' />
            <cms:field 'k_page_title' />
            <cms:field 'k_comments_count' />
            <cms:field 'k_page_foldertitle' />
            <cms:block 'publish_date' >
                <cms:field 'k_page_date' ><cms:date k_page_date format='d.m.Y' /></cms:field>
            </cms:block>
            <cms:field 'k_actions' />
        </cms:block>


Since my extended users template is /users/index.php and it also has smart_embed tag within cms:template block (all my templates actually have cms:smart_embed), a correct method to override k_page_date would be editing '/snippets/template_editables/users-index-default.html' snippet. It connects to 'default.html' (correct is to say 'extends' default.html) and changes 'publish_date' block's content. As usual 'users-index-default.html' holds all my regular editables for users.

Code: Select all
<cms:extends 'template_editables/default.html' />

<cms:block 'publish_date' >
    <cms:field 'k_page_date' header='Activated' ><cms:date k_page_date format='j M Y h.i a' /></cms:field>
</cms:block>

<cms:block 'editables'>
    <!--
        If additional fields are required for users, they can be defined here in the usual manner.
    -->
    <cms:editable type='text' name='firstname' label='First Name' required='1' validator_msg='required=Provide your First Name' />
    <cms:editable type='text' name='lastname' label='Last Name' required='1'  validator_msg='required=Provide your Last Name' />
    <cms:editable type='datetime' name='dateofbirth' label='Date of birth' />

</cms:block>


Now, all templates will have date listed as 'd.m.Y' and users template as 'j M Y h.i a'.

Please note, that since we also have <cms:block 'config_list_view_inner'> in 'default.html' we could override this block completely. Let's change columns in my users template adding 'email' to list-view. We can skip overriding 'publish_date' block individually, since we redefine the complete set of fields by changing content of 'config_list_view_inner' block.
Code: Select all
<cms:extends 'template_editables/default.html' />

<cms:block 'config_list_view_inner'>
    <cms:field 'k_selector_checkbox' />
    <cms:field 'k_page_title' />
    <cms:field 'email' header='Email Address'><cms:show extended_user_email /></cms:field>
    <cms:field 'k_page_date' header='Activated' ><cms:date k_page_date format='j M Y h.i a' /></cms:field>
    <cms:field 'k_actions' />
</cms:block>


<cms:block 'editables'>
     ....
</cms:block>



In conclusion, cms:smart_embed and cms:block are powerful enough to make things so much easier and achieve the goal with a single line. In future, if I need to make all my clonable templates searchable, I can for example add "searchable='1' " to 'default.html' and it is done!
<cms:config_list_view searchable='1' >


Regards