How to get names of relevant viewers?

In this example, we will read the list of viewers with the sitemap functionality and put it into the variable $TEST. We will then iterate through this list to print its elements.

You can use this example to get all viewer names that support some functionality.


Theory

Note that a viewer is a module designed to read specific database records located at the URLs associated with that viewer.

The first segment in such URLs is always equal to the viewer name. For example, the locator https://your.site/news/some-url-path is associated with the News viewer.

And next example. Any locators like listed below are associated with the Search viewer:
https://your.site/search,
https://your.site/search/some-page-number,
https://your.site/search?q=some-query,
https://your.site/search/some-page-number?q=some-query,
https://your.site/search/some-url-path,
https://your.site/search/some-url-path/some-page-number.

However, a viewer module may provide full or partial functionality depending on the goals of its developer. In this case, for some pages of the website, it may be important to get a list of viewers that correspond to the functionality of this page.

Therefore, unsuitable viewers are excluded from the resulting list if they do not have a template in the wesite theme that corresponds to such functionality.

To exclude unsuitable viewers, you need specify a relevancy pattern as an input parameter to the getViewers method.

Source Code

Please paste this code snippet into your template to see how it works.

Let's experiment with a template like tiny.news.feed/Themes/default/404.tpl by pasting code into it and then opening some non-existent page associated with that template.

<?php
    $TEST = $cms->getViewers('*-sitemap.tpl');
    foreach ( $TEST as $name ) {
        echo $name . ' <br>';
    }
?>

Note that the $cms variable is a system pointer to your web application. And getViewers is a public method for reading the viewer names. If you are interested in the algorithm of this method, look at the file tiny.news.feed/Application.php.

* This page is a demo post designed to display page content for testers. You need delete this page when you run the website in production mode.