Forum for discussing general topics related to Couch.
8 posts Page 1 of 1
Hello everyone, i started learning CouchCMS a couple of days ago and i think it's an amazing work!
I read all the documentation but still have doubts about accessing related_pages information from another template.

I created a dummy site with the aim to display race results trying to minimize the data entry.
I need to display the race results in different pages of the site.

I started creating the "entity" pilot, so that i could insert the data about the pilots only once: this template is clonable but not executable, since i'm not interested in displaying their profile in a dedicated page.
Code: Select all
<!-- pilots.php -->
<?php require_once('couch/cms.php'); ?>
   <cms:template clonable='1' executable='0'>

      <cms:editable name="nome" label="Nome pilota" type="text" />
      <cms:editable name="team" label="Team pilota" type="text" />
      <cms:editable name='foto' label='Foto pilota' desc='' type='image' />

   </cms:template>
<?php COUCH::invoke(); ?>


Then i created a page called rankings to display the general classification (pilots' name, their team and the points they earned). In this page i created a 'relation' so i could pick the pilot from a dropdown menu. This template is not clonable, since i want just one page for all rankings.

Code: Select all
<!-- it_IT/ranking.php -->
<?php require_once('couch/cms.php'); ?>

<cms:template clonable='0' executable='1'>
   <!-- up to 5 positions -->
   <?php for($i=1;$i<=5;$i++){
      ?>
      <cms:editable name="posizione_<?php echo $i?>" label="Numero posizione" type="text"><?php echo $i?></cms:editable>
      <cms:editable type='relation' name='ranking_pilots_<?php echo $i?>' masterpage='pilots.php' has='one' label='Pilota' />
      <cms:editable name="punti_<?php echo $i?>" label="Punti" type="text" />
      <cms:editable name="gare_<?php echo $i?>" label="Gare totali" type="text" />
   <?php
   }
?>
</cms:template>

<?php for($i=1;$i<=5;$i++){ ?>
   Position: <cms:show posizione_<?php echo $i?> /><br>   
   Points: <cms:show punti_<?php echo $i?> /><br>
   Total Races: <cms:show gare_<?php echo $i?> /><br>
   
   <cms:related_pages 'ranking_pilots_<?php echo $i?>' >
      <img src="<cms:show foto/>" /><br/>
      <h4><cms:show nome /></h4>
      <h5><cms:show team /></h5>
   </cms:related_pages>
<?php } ?>

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


So far, so good :)


Now the question is: how can i display the rankings and the pilots information in the homepage of the site, getting all the info from the 'it_IT/ranking.php' non-clonable template?
Really cannot figure out how to do this :|

I tried to do something like this, but with no results :( (the total points are displayed but the related_pages block is not being executed..)

Code: Select all
<!-- index.php -->
<?php require_once('couch/cms.php'); ?>
...
   <cms:pages masterpage='it_IT/ranking.php'>
      <?php for($i=1;$i<=5;$i++){ ?>
         Total points: <cms:show punti_<?php echo $i?>/><br/>
         <cms:related_pages 'ranking_pilots_<?php echo $i?> 'masterpage="pilots.php">
            Pilot's name: <cms:show nome_<?php echo $i?>/><br/>
            Pilot's team: <cms:show team_<?php echo $i?>/>
         </cms:related_pages>
      <?php } ?>
   </cms:pages>
...
<?php COUCH::invoke(); ?>


Can you help me?
(sorry for my bad english, i tried to do my best so you could understand the issue..)

Thank you so much!
Hi @fish and welcome :)

Your code:
Code: Select all
<cms:related_pages 'ranking_pilots_<?php echo $i?> 'masterpage="pilots.php">

Try this:
<cms:related_pages 'ranking_pilots_<?php echo $i?>' >

Note, that I removed masterpage parameter, because cms:related_pages is already running inside the context of its template, and it eventually solved a missing space between single quote and masterpage.

Also, I see you use a lot of "<?php for($i=1;$i<=5;$i++){ ?>". Couch has cms:repeat tag (http://couchdocs/tags-reference/repeat.html), which does essentially the same :)
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
Thank you trendoman for your superfast reply!

About the for loop, i simplified the code, originally the source involved a php constant instead of the number 5:
<?php for($i=1;$i<=MAX_PILOTI;$i++){ ?>
Is it possible to use the php constant MAX_PILOTI in the couchcms tag?

-----------

About retriving the pilots data, unfortunately removing the masterpage parameter didn't solve the issue :(
Maybe i missed something introducing my issue, so i'm including a simplified version of my index.php, just in case i omitted to declare some variable in the <cms:template tag.

Code: Select all
<!-- index.php -->
<?php require_once('../../couch/cms.php'); ?>

<cms:template clonable='1' executable='0'>
   <cms:editable name="nomecircuito" label="Nome Circuito" type="text" required="1" />
</cms:template>

<html><body>
   <cms:show nomecircuito/><br/>

   <cms:pages masterpage='it_IT/ranking.php'>
      <?php for($i=1;$i<=MAX_PILOTI;$i++){ ?>
         <cms:set punti_<?php echo $i?> = "<cms:show punti_<?php echo $i?> />"/>
         <cms:related_pages 'ranking_pilots_<?php echo $i?>'>
            <cms:set nome_<?php echo $i?> = "<cms:show nome />"/>
            <cms:set team_<?php echo $i?> = "<cms:show team />"/>
            Pilot's name: <cms:show nome/><br/>
            Pilot's team: <cms:show team/>
          </cms:related_pages>
         <?php } ?>

      <cms:show punti_1/> - <cms:show nome_1/> - <cms:show team_1/><br/>

   </cms:pages>
   
</body></html>
<?php COUCH::invoke(); ?>

The variable punti_1 is correctly displayed.
The nome_1 and team_1 variables are not being declared and nothing is printed in:
Pilot's name: <cms:show nome/><br/>
Pilot's team: <cms:show team/>

It seems that the code inside <cms:related_pages is not being executed at all.

I don't get it :| should i declare some relation between 'it_IT/ranking.php' and 'index.php'? Or should i mention 'pilots.php' somewhere, since the variables nome and team are declared in that template?

Thanks for your support!
Anna
Just to double check, you've gone into the admin panel and assigned the relation to each pilotes cloned page correct?
Image
Ok, I can't see the whole not reduced code, and can't debug potential php problems. :(

Please, align your code up to the completely working sample and let us know how it works for you :)

Template Pilots:
Code: Select all

<?php require_once( '_admin/cms.php' ); ?>
<cms:template title='Pilots' clonable='1' > 
 
  <cms:editable name='team'          type='text'      label='Team'    order='' />
 
</cms:template>

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



Template Rankings:

Code: Select all

<?php require_once( '_admin/cms.php' ); ?>
<cms:template title='Ranking' clonable='0' > 
 
  <cms:pages masterpage='pilots.php' limit='1'> <cms:set total_pilots = k_total_pages scope='global' /></cms:pages>
  <cms:repeat total_pilots startcount='1' >
 
      <cms:editable name="position_<cms:show k_count />"          label='Numero posizione' type='text' />
      <cms:editable name="ranking_pilots_<cms:show k_count />"     type='relation' masterpage='pilots.php' has='one' label="Pilota_<cms:show k_count />" />
 
  </cms:repeat>
 
</cms:template>


<cms:repeat total_pilots startcount='1' >

   <cms:related_pages "ranking_pilots_<cms:show k_count />" >
   
      <cms:ignore><cms:dump /></cms:ignore>
      
      <cms:show k_page_title /><br>
      <cms:show team />
      <hr>
   
   </cms:related_pages>

</cms:repeat>

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




Please note, that number of available editables for ranking system is assigned dynamically visiting template as superadmin, according to the total number of pages in template pilots.php

Also I didn't place 'name' editable for pilots and used title of each cloned page.

Hope it works for you as it works for me here.
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
Thanks for your feedback trendoman and sorry for my late reply!
Your code is perfectly working (my ranking.php was working too, but the code was horrible compared to yours :D).

Unfortunately i still cannot access to the ranking information (name of the first 5 pilots classified) from the homepage.

Do you think it can be accomplished?

Code: Select all
<!-- index.php -->
<?php require_once('couch/cms.php'); ?>

<html><body>

   <cms:pages masterpage='it_IT/ranking.php'>
      <?php for($i=1;$i<=5;$i++){ ?>
         <cms:related_pages 'ranking_pilots_<?php echo $i?>'>
            Pilot's name: <cms:show nome/>
          </cms:related_pages>
         <?php } ?>

   </cms:pages>
   
</body></html>
<?php COUCH::invoke(); ?>


Thank you so much,
A.
Does it work if you write it manually (change cmsz to cms)?

Code: Select all

<cmsz:pages masterpage='it_IT/ranking.php'>

           <cmsz:related_pages 'ranking_pilots_1'>
            Pilot's name: <cmsz:show nome/>
          </cmsz:related_pages>
                  <cmsz:related_pages 'ranking_pilots_2'>
            Pilot's name: <cmsz:show nome/>
          </cmsz:related_pages>
                  <cmsz:related_pages 'ranking_pilots_3'>
            Pilot's name: <cmsz:show nome/>
          </cmsz:related_pages>
                  <cmsz:related_pages 'ranking_pilots_4'>
            Pilot's name: <cmsz:show nome/>
          </cmsz:related_pages>
                  <cmsz:related_pages 'ranking_pilots_5'>
            Pilot's name: <cmsz:show nome/>
          </cmsz:related_pages>
         
   </cmsz:pages>


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
Hello trendoman!
Nope, nothing is printed, not even the label "Pilot's name:" :(
It looks like the entire blocks <cms:related_pages..></cms:related_pages> are ignored :|

Thank you,
Anna
8 posts Page 1 of 1