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

I have a template "tags.php" that is used to create tags.
Code:
Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template title='Business Tags' clonable='1'  parent="_listing_" order='1' />
<?php COUCH::invoke(); ?>


To create a relation I have used the following in another template (named business.php) as:
Code: Select all
<cms:editable name='tags' type='relation' masterpage='tags.php' label='Select Tags for Business' desc='if a tag doesnot exist, add it through Business Tags' order='20' />


To list the tags on the "business.php" template I have used the following:
Code: Select all
<cms:capture into='my_tags'>
                                <cms:related_pages 'tags' >
                                    <cms:show my_tags />
                                    <a href="<cms:show k_page_link />">
                                        <cms:show k_page_title />
                                    </a>
                                </cms:related_pages>
                            </cms:capture>
                            <cms:if my_tags >
                                <a href="#">
                                    <i class="fa fa-tag"></i> Tags
                                </a>
                                <cms:show my_tags />
                            </cms:if>


Now I am creating a JSON file for displaying the data of the "business.php" template in a JSON format.

The Problem
I am unable to display the tags in the JSON.

The JSON output is produced by a template "businessJSON.php". I have tried variations but no solution. So i am posting the crude code here, wherein i am looking for the inputs in the tag#<cms:show k_count />":"" section.
Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:template title='Business Listing JSON' order='1005' icon='home' hidden='1 '/>
<cms:content_type 'application/json'/>
<cms:set catId="<cms:gpc 'catId' method='get' />" />
<cms:set busId="<cms:gpc 'busId' method='get' />" />
<cms:set cat_count='0' scope='global' />
<cms:if catId>
   <cms:query sql="SELECT id AS `k_folder_id`,  name AS `k_folder_name`, title AS `k_folder_title` FROM `couch_folders` AS f WHERE f.id = '<cms:show catId />' AND f.template_id = '24'" limit='1'>
   <cms:set selected_folder = k_folder_name scope='global' />
   <cms:no_results >Error: No Departments found!</cms:no_results>
   </cms:query>
</cms:if>
<cms:if catId && busId>
{
   "business":[
      <cms:pages masterpage='business-listing.php' folder=selected_folder id=busId >
      {   
                        "BusinessName":"<cms:addslashes><cms:show k_page_title /></cms:addslashes>",
         "tags": [
            {
               "tag#<cms:show k_count />" : "/*What to do here to display the tags related to only the business in consideration*/"<cms:if '<cms:not k_paginated_bottom />' >,</cms:if>
            }
         ]
      }<cms:if "<cms:not k_paginated_bottom />">, </cms:if>
      </cms:pages>
   ]
}
<?php COUCH::invoke(); ?>


Regards,
GenXCoders
Image
where innovation meets technology
I have used the following code, which helps me achieve what i wanted:
Code: Select all
<cms:related_pages 'tags' masterpage='tags.php' order='asc'>
    "tag#<cms:show k_count />" : "<cms:show k_page_title />"<cms:if "<cms:not k_paginated_bottom />">, </cms:if>
</cms:related_pages>


So the final code to:
1. list the tags in JSON
2. list the tags relating to the particular business.php
is,

Code: Select all
{
   "business":[
      <cms:pages masterpage='business-listing.php' folder=selected_folder id=busId>
      {
                         /* Other Values Here */
                         "tags":
                         [
             {
               <cms:related_pages 'tags' masterpage='tags.php' order='asc'>
                       "tag#<cms:show k_count />" : "<cms:show k_page_title />"<cms:if "<cms:not k_paginated_bottom />">, </cms:if>
               </cms:related_pages>
            }
         ]
                 }<cms:if "<cms:not k_paginated_bottom />">, </cms:if>
            </cms:pages>
   ]
}


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