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

When I run this code, the count is always 0.

Code: Select all
<cms:php>
   global $FUNCS;
   $title = 'This is the page title';
   $tag = 'cms:pages';
   $html =<<<EOS
      <$tag
      _masterpage='clonablepages.php'
      page_title='{$title}'
      show_future_entries='1'
      count_only='1'
      />
EOS;

   $count = $FUNCS->embed($html, $is_code=1);
   if($count == 0) {
      //Nothing found, do something.
   }
</cms:php>


But when I replace within the EOS, page_title="{$title}" with page_title="This is the page title" (remove the manual set php variable) I get a valid count number.

I was using KK's post as reference: https://www.couchcms.com/forum/viewtopic.php?f=4&p=19828#p19829 and this will be in a foreach loop where the title will pull from an array.

Any ideas what I am doing wrong?
Did you try using just
page_title='$title'
(i.e. no curly braces)?
KK wrote: Did you try using just
page_title='$title'
(i.e. no curly braces)?


I did now, also returned with 0. I also tried some other ways, took a screenshot of my code editor overlapping chrome browser for results of the page. Only 1 returns a successful count of 1.

Code from the screenshot:
Code: Select all
<cms:php>
   global $FUNCS;
   $title = 'This is the title';
   $html = "<cms:pages masterpage='clonablepages.php' page_title='This is the title' show_future_entries='1' count_only='1' />";

   $count = $FUNCS->embed($html, $is_code=1);
   echo $count;
</cms:php>
<br>
<cms:php>
   global $FUNCS;
   $title = 'This is the title';
   $html = "<cms:pages masterpage='clonablepages.php' page_title='{$title}' show_future_entries='1' count_only='1' />";

   $count = $FUNCS->embed($html, $is_code=1);
   echo $count;
</cms:php>
<br>
<cms:php>
   global $FUNCS;
   $title = 'This is the title';
   $html = "<cms:pages masterpage='clonablepages.php' page_title='$title' show_future_entries='1' count_only='1' />";

   $count = $FUNCS->embed($html, $is_code=1);
   echo $count;
</cms:php>
<br>
<cms:php>
   global $FUNCS;
   $title = 'This is the title';
   $tag = 'cms:pages';
   $html =<<<EOS
      <$tag
      _masterpage='clonablepages.php'
      page_title='$title'
      show_future_entries='1'
      count_only='1'
      />
EOS;

   $count = $FUNCS->embed($html, $is_code=1);
   echo $count;
</cms:php>


Here is the clonablepages.php template, which has 2 pages in it. The default page and a page with k_page_title of This is the Title
Code: Select all
<?php require_once('couch/cms.php'); ?>
<cms:template title='Clonable Pages' order='9' clonable='1' hidden='1' >
   <cms:editable type="text" name="page_content" label='Page Content' order='1' required='1' />
</cms:template>
<?php COUCH::invoke(); ?>

Attachments

I noticed an underscore before masterpage here:
Code: Select all
<$tag
      _masterpage


Is it expected?
trendoman wrote: I noticed an underscore before masterpage here:
Code: Select all
<$tag
      _masterpage


Is it expected?


No, it was for the create EOS string I did and I had just left it there accidentally. Thanks for spotting that - I removed the underscore and the last option is resulting a count in the check, so I was able to get my script working with the foreach loop.

I find the 2nd and 3rd methods a bit easier to write with than the 4th EOS method, but can't be picky if it works it works. :)

Thanks!
You are welcome.
2d and 3rd methods can be used with making a tag a string.
Code: Select all
$html = "<" . "cms:pages ...
6 posts Page 1 of 1