Search
Other Articles Anywhere questions
Forum

Test for Existence of Page

Jay Stevens's Avatar Jay Stevens
I am using Articles Anywhere Pro Ver. 14.1.1 with PHP 7.4.

I want to test for the existence of a page. If that page exists, I want to show that page. If not, I want to show a boilerplate page.

I have a variable $squad_no which is a string length 4. A page with alias 2820 exists. A page with alias 2520 does not exist. A page with title "Boilerplate" exists.

I tried the following code in a Joomla 4 custom module using Sourcerer:
{source}
<?php
    $squad_no="";
  $art =

         '{article alias="' . $squad_no . '"}

          {if [alias]="' . $squad_no . '"}{article-next alias = "' . $squad_no . '"}[article] {/article-next}

          {else} {article-next2 title = "Squadron Boilerplate"}[article] {/article-next2}

          {/if}

          {/article}';

   echo $art;
?>
{/source}
When $squad_no is set to "2820", the page with alias "2820" displays. When $squad_no is set to "2520" the page with alias "2520" does not exist, but the {else} rule is not followed and the "Squadron Boilerplate" page is not displayed.

How can I test for the existence of a page with a given alias?
Peter van Westen's Avatar Peter van Westen ADMIN
What is inside the {article} tags will only be output for articles that tag returns.
So if the tag returns no articles (for instance in your case when the article doesn't exist), then it will never get to that if/else.

What you need is: docs4.regularlabs.com/articlesanywhere/p...gs#output-when-empty
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription