I am new at this...How find if a page exists?

Permalink
I am setting up a muti language site, but I need to check if page is not found in the alternate language, be able to fall back to the native language. So how can I can if a page if there via the alias?

Example,
English
/home
/about
/search

Chinese
/zh/home
/zh/about

Now if some visitor, enter the chinese site, the page /zh/search will not be show as there is no such page, alternatively, when someone enter /zh/search they will be show /search and the fall back page is /seach for /zh/search

Can anyone show me how to check for a page alias to see if it exists, the below code is applied to the header, as such if the page for that language is not there, the language selection will not be shown

<?php
      // get current cPath and replace /zh to /
         $pagevieworiginal = View::getViewPath();
      if ( stristr($pagevieworiginal, '/zh') ) {
$pageviewreplaced = str_replace ('/zh', '', $pagevieworiginal);
$alternatelanguage = 'English';
      } else {
$pageviewreplaced = '/zh'. $pagevieworiginal;
$alternatelanguage = '中文';
      }
      ?>
      <div id="languageSelect">
         <a href="<?php echo BASE_URL . DIR_REL . $pageviewreplaced ?>/"><?php echo $alternatelanguage ?></a></div>

 
ScottC replied on at Permalink Reply
ScottC
$page = Page::getByPath('zh/about');

if(!$page->isError()) //page is not error
then do something.

Thank you to Andrew on this when i started writing the blog app. A call to request and instance of page will return a page object, but it'll be error.
begeto replied on at Permalink Reply
Thanks.

It works.

I did this to the header so that it can switch language and have a fall back to the default language page.

Sharing..

<div id="headerNav">
  <?php
    if ($c->getCollectionAttributeValue('simplified_chinese_menus')) {
      $block = Block::getByName('Simplified Chinese Menus');
      if( is_object($block) ) $block->display();
    } else {
      $block = Block::getByName('English Menus');
      if( is_object($block) ) $block->display();
    }
  ?>
</div>
<?php
      // get current cPath and replace /zh to /
         $pagevieworiginal = View::getViewPath();
      if ( stristr($pagevieworiginal, '/zh') ) {