Docs: The site, the visitor and the request

The site, the visitor and the request

The site, the visitor and the request: site, visitor, hasModule, query, currentUrl, lang, languages and langUrl.

The site and the visitor #

site() #

The site's identity (P): {name, description, url, lang, logo, owner: {name, tagline}, social: {email, github, linkedin, website, x}}. Every value is a string. Each social value is safe in an href. This is the only way a theme reaches the settings.

<?= htmlspecialchars($this->site()['name'], ENT_QUOTES, 'UTF-8') ?>

visitor() #

Who is looking (P): {signed_in, name, verified, staff, account_url, login_url}. Never an id, an email or a role. A page that shows a signed-in visitor is never served from the page cache.

<?php $me = $this->visitor(); ?>
<?php if ($me['signed_in']): ?>
  <a href="<?= $me['account_url'] ?>"><?= htmlspecialchars($me['name'], ENT_QUOTES, 'UTF-8') ?></a>
<?php else: ?><a href="<?= $me['login_url'] ?>">Sign in</a><?php endif; ?>

hasModule($id) #

Whether a module is installed and running.

<?php if ($this->hasModule('blog')): ?><a href="/blog">Blog</a><?php endif; ?>

The request #

query($key, $kind = 'text', $default = null) #

One value from the address's query string, in the shape you ask for, else $default. Kinds: 'int' (1 to 1,000,000), 'text' (E, at most 200 characters), 'slug', or a list of allowed strings. Reading a key the address carries keeps the page out of the page cache.

<?php $q = $this->query('q'); $n = $this->query('page', 'int', 1); ?>

currentUrl($set = []) #

This page's own address in the request's language, with the query values you set (E). It is the page's canonical path, never the address as the visitor typed it.

<a href="<?= $this->currentUrl(['page' => $n + 1]) ?>">Next page</a>

lang() and contentLang() #

The language codes of the request and of the page's content. Calling either claims <html lang>.

<html lang="<?= $this->contentLang() ?>">

languages() #

The language switcher as {code, name, url, current, available} (P). Calling it claims the switcher.

<?php foreach ($this->languages() as $l): ?><a href="<?= htmlspecialchars($l['url'], ENT_QUOTES, 'UTF-8') ?>"><?= htmlspecialchars($l['name'], ENT_QUOTES, 'UTF-8') ?></a><?php endforeach; ?>

langUrl($path) #

A same-site path in the request's language (P).

<a href="<?= htmlspecialchars($this->langUrl('/contact'), ENT_QUOTES, 'UTF-8') ?>">Contact</a>