How to get names of installed viewers?

In this example, we will read the list of installed viewers 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 the names of the viewers installed in your web application.


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.

All viewer modules are located at a common folder named tiny.news.feed/Viewers. Each viewer is a named subfolder (for example, tiny.news.feed/Viewers/Search) and a nested PHP file of the same name (for example, tiny.news.feed/Viewers/Search/Search.php) with a certain class and methods declared there.

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();
    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.

And here you can read the answer to another question regarding reading a list of viewers that support only specific functionality.

* 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.