{sitemap}

Lists the pages of the application, read from the file tree, as rows with page, url and lastmod.

Navigation Tag pairs

Syntax

{sitemap} ... {$page} {$url} {$lastmod} ... {/sitemap}
{sitemap 'dir'} ... {/sitemap}

Parameters

dir
Optional: a directory of the application - 'docs'; only the pages below it are listed. A name that is no directory, or starts with _, is an error under the strict check.

Description

{sitemap}...{/sitemap} walks the application's directories and makes a row of every page - in PAD every page is a file, so no list of routes is needed to know them. Each row has page (docs/intro), url (the absolute address, ?docs/intro, or the clean form under $padCleanUrls) and lastmod (Y-m-d, the newest of the page's files). The rows come per directory: its index first, then its other pages, then its subdirectories; a directory's index has the directory as its url.

Left out are the entries that are no pages to visit: _ and dot entries, a directory holding a _guard.php, a bracketed route (products/[id]), a page with no template whose PHP only redirects, restarts or writes, a page whose template says {meta sitemap=false}, and every page or directory listed in $padSitemapSkip.

A first parameter limits the list to one directory - {sitemap 'docs'} - for a menu of a section. The rows are ordinary data, so the handling options apply: first=, where=, sort='lastmod DESC' for "recently changed".

With $padSitemap = TRUE in the configuration the same list answers ?sitemap.xml as the sitemap protocol's XML, and ?robots.txt points to it, as long as the application has no page of that name.

Examples

The pages of a directory

A row per page, read from the file tree - the index first, then the pages, then the subdirectories.

Templateexamples/sitemap/1-list.pad
<ul>
  {sitemap 'examples/sitemap/site'}<li>{$page}</li>{/sitemap}
</ul>
Resultopen alone
  • examples/sitemap/site/index
  • examples/sitemap/site/about
  • examples/sitemap/site/contact
  • examples/sitemap/site/docs/index
  • examples/sitemap/site/docs/intro

As links

url is the address of each page; a directory's index is the directory.

Templateexamples/sitemap/2-links.pad
<nav>
  {sitemap 'examples/sitemap/site/docs'}<a href="{$url}">{$page | after('site/')}</a> {/sitemap}
</nav>

With the date of change

lastmod is the newest file time of a page - Y-m-d - so it changes whenever a file does.

Templateexamples/sitemap/3-lastmod.src
<table>
  {sitemap}<tr><td><a href="{$url}">{$page}</a></td><td>{$lastmod}</td></tr>{/sitemap}
</table>

See also

  • {files} Scans a directory and iterates its entries, with path, file, ext, item and dir for each.
  • {dir} Lists the names in a directory, one occurrence each - the plain version of files.
  • {pager} Page links for a tag written with the page option: first and last, a window round the current page, previous and next.
  • {meta} The page's metadata - a title, a layout, a cache time or any value - read while the page is assembled.