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

Is there a way to create a folder structure as in this post https://www.couchcms.com/forum/viewtopic.php?f=2&t=8163&hilit=Json+structure

But from the front end.

Approach method:
1. a template with 3 fields
- folder name (text field)
- folder dropdown (dropdown list of all folders from first field)
- set if folder is root parent (checkbox) ie, the folder can never have a parent

2. Folders JSON to be generated as in the link above, to the n-th level.

3. The JSON will then output all is folder root parents, which will be collected into an android application drawer.

Please comment.

Regards,
Aashish
Image
where innovation meets technology
3 different templates + relations between them are a better solution.
Forget about folders, since even 2-3k of folders will be unresponsive heavy dropdown.

With relations it will be possible to have cms:related_pages at hands with all bells and whistles of cms:pages (paginated_top, bottom, counts etc.)
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
Actually folders are not going to be more than 9 to 10, including sub folders. Hence I was considering that. Whats your call on it @trendoman and all couchies

Actually the front end and the backend is only the couch control panel and nothing more. I have also removed the view buttons from the admin panel.
Image
where innovation meets technology
I have created a JSON for the dynamic folders.

code for dynamic folders is :
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>

   <cms:template title='Add Employee/Member' order='1' clonable='1' dynamic_folders='1'>
      <cms:editable name='contact' label='Contact Details' type='group' order='1' />
         <cms:editable name='mob_o' label='Mobile (Official)' type='text' group='contact' />
         <cms:editable name='mob_p' label='Mobile (Personal)' type='text' group='contact' />
         <cms:editable name='tel_o' label='Landline (Office)' type='text' group='contact' />
         <cms:editable name='tel_r' label='Landline (Residence)' type='text' group='contact' />
      <cms:editable name='address' label='Postal Details' type='group' order='2' />
         <cms:editable name='address_o' label='Address (Office)' type='textarea' no_xss_check='1' group='address' />
         <cms:editable name='address_r' label='Address (Residence)' type='textarea' no_xss_check='1' group='address' />
      <cms:editable name='online' label='Online Details' type='group' order='3' />
         <cms:editable name='email_o' label='Email (Official)' type='text' group='online' />
         <cms:editable name='email_p' label='Email (Personal)' type='text' group='online' />
   </cms:template>

<?php COUCH::invoke(); ?>


Now I generated a JSON for only the Parent departments as:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
   
   <cms:content_type 'application/json'/>
   
   {
      "departments" :
      [
         <cms:set department_count='0' />
         <cms:folders masterpage='emp.php' order='asc' depth='1'>
         {
            "deptId"    :    "<cms:show k_folder_id />",
            "deptName"   :   "<cms:show k_folder_title />",
            "hasChild"   :   "1"            
         }
         <cms:incr department_count />
         <cms:if department_count!=k_total_folders> , </cms:if>
         </cms:folders>
      ]
   }
   
<?php COUCH::invoke(); ?>


that gives a n output as:
Code: Select all
{
    "departments": [
        {
            "deptId": "1",
            "deptName": "Development",
            "hasChild": "1"
        },
        {
            "deptId": "11",
            "deptName": "Management",
            "hasChild": "1"
        },
        {
            "deptId": "3",
            "deptName": "Research &amp; Development",
            "hasChild": "1"
        },
        {
            "deptId": "2",
            "deptName": "Sales",
            "hasChild": "1"
        }
    ]
}


I then created a now JSON output for the Child Departments using the code:
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
   
   <cms:content_type 'application/json'/>
   
   {
      "childDept"   :
      [         
         <cms:set child_department_count='0' />
         <cms:folders masterpage='emp.php' order='asc' depth='1'>

            <cms:if k_folder_immediate_children >
               <cms:folders masterpage='emp.php' order='asc' childof=k_folder_name depth='1'>
               {
                  "deptId"   :   "<cms:show k_folder_id />",
                  "deptName"   :   "<cms:show k_folder_title />"
               }<cms:if "<cms:not k_paginate_bottom/>"> , </cms:if>
               </cms:folders>
            </cms:if>
            
         </cms:folders>
      ]
   }
   
   <?php COUCH::invoke(); ?>


and that generates the following output, which is has an error. the out put is:
Code: Select all
   
      
   {
      "childDept"   :
      [         
                  
                                          {
                  "deptId"   :   "6",
                  "deptName"   :   "Android"
               } ,                               {
                  "deptId"   :   "5",
                  "deptName"   :   "Dot Net"
               } ,                               {
                  "deptId"   :   "4",
                  "deptName"   :   "PHP"
               } ,                                        
         
                                          {
                  "deptId"   :   "13",
                  "deptName"   :   "Development"
               } ,                               {
                  "deptId"   :   "14",
                  "deptName"   :   "Research &amp; Development"
               } ,                               {
                  "deptId"   :   "12",
                  "deptName"   :   "Sales"
               } ,                                        
         
                                          {
                  "deptId"   :   "10",
                  "deptName"   :   "Products"
               } ,                                        
         
                                          {
                  "deptId"   :   "9",
                  "deptName"   :   "Mobile Application"
               } ,                               {
                  "deptId"   :   "8",
                  "deptName"   :   "Webportal"
               } ,                               {
                  "deptId"   :   "7",
                  "deptName"   :   "Website"
               } ,                                        
               ]
   }
   
   
0



THE PROBLEM:
1. There is a comma appearing at the last entry:
} , {
"deptId" : "7",
"deptName" : "Website"
} ,

How can I stop it!

2. a ')' (zero) appears at the end of the json. How to stop its auyout? How to stop it?
Image
where innovation meets technology
Ok, this is now not a feature/code-request, but a good question :) Since you are a good boy and very specific and I will try to answer that :) No offense :D

First, I want to share something that you might find helpful to prevent any undesired output.
Code: Select all
<cms:abort is_404='0' >
.... any couch code for ajax/json related here
</cms:abort>

or
Code: Select all
<cms:capture into='out' >
.... any couch code for ajax/json related here
</cms:capture>
<cms:abort msg=out is_404='0' />


Both samples above make couch NOT output anything else on the page - no other code than what's inside the cms:abort.
It is helpful with cms:is_ajax tag (just a mention, probably not related).

I will try to address the comma issue a bit later today. Do you use couch2 code or 1.4.7? It is important, because with <cms:dump /> inside <cms:folders > in couch2 more variables available.

Edit: Quick-spotted k_paginate_bottom should be k_paginated_bottom. Think, this will help.
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
EDIT:
@tredoman: Bro its solved.. thanks a ton!!!


@trendoman:

None of the following worked.

Neither
Code: Select all
<cms:abort is_404='0' >
.... any couch code for ajax/json related here
</cms:abort>

Nor
Code: Select all
<cms:capture into='out' >
.... any couch code for ajax/json related here
</cms:capture>
<cms:abort msg=out is_404='0' />

The 0 at the end is still output!
What can be done for that?
Image
where innovation meets technology
6 posts Page 1 of 1