Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files

add non-destructive template exclusions

  • Loading branch information...
mikerockett committed Dec 26, 2017
1 parent f68c374 commit 4981b9b537bce556ba15d4eacac0d095fea170da
Showing with 47 additions and 5 deletions.
  1. +1 −1
  2. +3 −1 MarkupSitemap.module.php
  3. +18 −1 MarkupSitemapConfig.php
  4. +25 −2 src/Traits/BuilderTrait.php
@@ -1,6 +1,6 @@
"title": "Sitemap",
"version": "0.3.2",
"version": "0.3.3",
"author": "Mike Rockett",
"summary": "Renders a sitemap for your ProcessWire powered site. Supports multi-language, multi-site, and image sub-elements. Adapted from MarkupSitemapXML.",
"href": "",
@@ -255,7 +255,9 @@ public function setupSettingsTab(HookEvent $event)
// We only need to proceed with this process if the current page's
// template has been assigned as configurable in the module's configuration.
if ($this->sitemap_include_templates !== null
&& in_array($page->template->name, $this->sitemap_include_templates)) {
&& in_array($page->template->name, $this->sitemap_include_templates)
&& !in_array($page->template->name, $this->sitemap_exclude_templates)
) {
// Get the settings tab inputfields
$inputFields = $event->return;
@@ -59,7 +59,7 @@ public function getInputFields()
// Add the template-selector field
$includeTemplatesField = $this->buildInputField('AsmSelect', [
'name+id' => 'sitemap_include_templates',
'label' => 'Templates with sitemap options',
'label' => $this->_('Templates with sitemap options'),
'description' => $this->_('Select which templates (and, therefore, all pages assigned to those templates) can have individual sitemap options. These options (shown in the Settings tab of the page editor) allow you to set which pages and, optionally, their children should be excluded from the sitemap when it is rendered; define which page’s images should not be included in the sitemap (provided that image fields have been added below); and, lastly, set an optional priority for each page.'),
'notes' => $this->_("**Removal/Restoration:** Removing a template from this list will not delete any page options applicable to it. However, they will also not be read when rendering the sitemap. As such, when restoring a template to this list after having removed it, any previous options saved for a page that uses this template will be used when rendering the sitemap. The only time sitemap options are deleted is when either the page in question is completely deleted after having been trashed, or when the module is uninstalled.\n\n**A note about the home page: ** This page cannot be excluded from the sitemap. As such, the applicable exclusion options will not be available when editing it."),
'icon' => 'cubes',
@@ -69,6 +69,23 @@ public function getInputFields()
// Add the template-selector field that disables template access to the module.
// The home template cannot be added to the exclusions list.
$excludeTemplatesField = $this->buildInputField('AsmSelect', [
'name+id' => 'sitemap_exclude_templates',
'label' => $this->_('Templates without sitemap access'),
'description' => $this->_('Select which templates (and, therefore, all pages assigned to those templates) should not have sitemap access.'),
'notes' => $this->_('**Note:** Adding a template to this list overrides template-level functionality defined above. If a template is listed here, its pages will not have access to any sitemap functionality, including options, and will not be included in the rendered sitemap. However, the template will not be removed from the options list above, in the case that you wish to easily restore it. As such, this is a non-destructive configuration option.'),
'icon' => 'remove',
'collapsed' => Inputfield::collapsedBlank,
foreach ($templates as $template) {
if ($template->id !== 1) {
$excludeTemplatesField->addOption($template->name, $template->get('label|name'));
// Add the image-field-selector field if image fields exist
if ($imageFields = $this->fields->find('type=FieldtypeImage') and $imageFields->count) {
$imageFieldsField = $this->buildInputField('AsmSelect', [
@@ -100,11 +100,34 @@ protected function addImages($page, $url, $language = null)
* Determine if a page can be included in the sitemap
* @param $page
* @param $options
* @return bool
public function pageIsIncludible($page, $options)
// If it's the home page, it's always includible.
if ($page->id === 1) {
return true;
// If the page's template is excluded from accessing Sitemap,
// then it's not includible.
if (in_array($page->template->name, $this->sitemap_exclude_templates)) {
return false;
// Otherwise, check to see if the page itself has been excluded
// via Sitemap options.
return !$options['excludes']['page'];
* Recursively add pages in each language with
* alternate language and image sub-elements.
* @param $page
* @return void
protected function addPages($page)
@@ -125,7 +148,7 @@ protected function addPages($page)
// If the page is viewable and not excluded or we’re working with the root page,
// begin generating the sitemap by adding pages recursively. (Root is always added.)
if ($page->viewable() && ($page->path === '/' || !$pageSitemapOptions['excludes']['page'])) {
if ($page->viewable() && $this->pageIsIncludible($page, $pageSitemapOptions)) {
// If language support is enabled, then we need to loop through each language
// to generate <loc> for each language with all alternates, including the
// current language. Then add image references with multi-language support.

0 comments on commit 4981b9b

Please sign in to comment.
You can’t perform that action at this time.