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 theNews
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. AndgetViewers
is a public method for reading the viewer names. If you are interested in the algorithm of this method, look at the filetiny.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.