fixed company name
This commit is contained in:
@@ -10,6 +10,7 @@ return [
|
||||
// 'debug' => false,
|
||||
|
||||
// 'site_name' => 'My Site',
|
||||
// 'twig_globals' => ['company_name' => 'My Company'],
|
||||
|
||||
// Docs: /admin/docs/matomo
|
||||
// 'matomo_url' => 'https://matomo.example.com/',
|
||||
|
||||
@@ -62,7 +62,7 @@ if ($config['debug']) {
|
||||
$cache->clear();
|
||||
}
|
||||
|
||||
$renderer = new Renderer($config['pages_dirs'], $cache, $adminAuthEnabled, $matomoUrl, $config['matomo_site_id'], $config['site_name'], $config['content_index_enabled'], $config['debug']);
|
||||
$renderer = new Renderer($config['pages_dirs'], $cache, $adminAuthEnabled, $matomoUrl, $config['matomo_site_id'], $config['site_name'], $config['content_index_enabled'], $config['debug'], $config['twig_globals'] ?? []);
|
||||
|
||||
// Every route under /admin/* — clear-cache, docs, users, and any admin
|
||||
// page a project adds later — is gated here, once, rather than in each
|
||||
|
||||
@@ -20,6 +20,16 @@ return [
|
||||
// footer copyright line in novaconium/pages/_layout/layout.twig.
|
||||
'site_name' => 'Novaconium Website',
|
||||
|
||||
// Extra project-specific values exposed to every Twig template as
|
||||
// globals, e.g. 'twig_globals' => ['company_name' => 'Acme Ltd.'] makes
|
||||
// {{ company_name }} available everywhere. Only keys listed here reach
|
||||
// Twig — the rest of this config (API secrets, DB paths) never does. A
|
||||
// key that collides with a framework global (site_name, matomo_url,
|
||||
// matomo_site_id, admin_auth_enabled, content_index_enabled, is_404)
|
||||
// is ignored; set those through their own config keys instead. See
|
||||
// /admin/docs/config.
|
||||
'twig_globals' => [],
|
||||
|
||||
// Matomo analytics. Leave both empty (the default) to disable tracking
|
||||
// entirely — the layout emits no tracking script at all in that case.
|
||||
// Set both via App/config.php to enable, e.g.:
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
{% block docs_content %}
|
||||
<h1>Configuration</h1>
|
||||
|
||||
<p><code>novaconium/config.php</code> holds the framework defaults — <code>pages_dirs</code>, <code>cache_dir</code>, <code>debug</code>, <code>site_name</code>, <code>matomo_url</code>, <code>matomo_site_id</code>, <code>admin_auth_enabled</code>, <code>db_connections</code>, <code>draft_routes</code> — and is not meant to be edited per-project, same as everything else under <code>novaconium/</code>.</p>
|
||||
<p><code>novaconium/config.php</code> holds the framework defaults — <code>pages_dirs</code>, <code>cache_dir</code>, <code>debug</code>, <code>site_name</code>, <code>matomo_url</code>, <code>matomo_site_id</code>, <code>admin_auth_enabled</code>, <code>db_connections</code>, <code>draft_routes</code>, <code>twig_globals</code> — and is not meant to be edited per-project, same as everything else under <code>novaconium/</code>.</p>
|
||||
|
||||
<p><code>App/config.php</code> ships with the skeleton as an empty, commented placeholder — uncomment (or add) whichever keys you want to change, returning an array of just those:</p>
|
||||
|
||||
@@ -54,6 +54,20 @@ return [
|
||||
|
||||
<p>See <a href="/admin/docs/seo">SEO</a> for the full list of overridable meta blocks. Pages that were already statically cached before this changes need <code>php novaconium/bin/clear-cache.php</code> to pick it up.</p>
|
||||
|
||||
<h2>Custom template globals</h2>
|
||||
|
||||
<p><code>twig_globals</code> (default <code>[]</code>) is how a project makes its own values available in every template. Any key you add to <code>App/config.php</code> is <em>not</em> visible to Twig on its own — only the framework's fixed globals (<code>site_name</code>, <code>matomo_url</code>, <code>matomo_site_id</code>, <code>admin_auth_enabled</code>, <code>content_index_enabled</code>, <code>is_404</code>) are. List anything else under <code>twig_globals</code>:</p>
|
||||
|
||||
<pre><code><?php
|
||||
// App/config.php
|
||||
return [
|
||||
'twig_globals' => [
|
||||
'company_name' => 'Acme Ltd.',
|
||||
],
|
||||
];</code></pre>
|
||||
|
||||
<p>Every template, layout, and sidecar-rendered page can then use <code>{% verbatim %}{{ company_name }}{% endverbatim %}</code>. The whole config array is deliberately not exposed, since it holds secrets such as <code>mailjet_api_secret</code>. A key that collides with a framework global is ignored — set <code>site_name</code> and the rest through their own config keys. As with <code>site_name</code>, already-cached pages need <code>php novaconium/bin/clear-cache.php</code> to pick up a change.</p>
|
||||
|
||||
<h2>Admin authentication</h2>
|
||||
|
||||
<p><code>admin_auth_enabled</code> (default <code>false</code>) gates every <code>/admin/*</code> route behind a session login against the <code>users</code> table — see <a href="/admin/docs/admin-auth">Admin authentication</a> for the full write-up, including roles (the first user is the admin; the rest are registered) and how the first user gets created. The same flag powers <a href="/admin/docs/access-control">Access control</a> (<code>Lib\Access</code>) for member/group-gated content. When left off, <code>/admin/*</code> is open, the login/users routes <code>404</code>, and <code>Access::require()</code> allows everything.</p>
|
||||
|
||||
@@ -228,7 +228,7 @@ Response::html(string $html, int $status = 200): self // type 'html', Cont
|
||||
|
||||
<p><code>Renderer</code> is the last thing a request touches, in <code>novaconium/bootstrap.php</code>: <code>Router::resolve()</code> produces a <code>Route</code>, <code>AdminAuth</code> optionally gates it, and then <code>Renderer</code> reads that same <code>Route</code> to actually produce output. It never talks back to <code>Router</code> or <code>AdminAuth</code> — by the time it runs, routing and auth are already decided, and its only inputs are the <code>Route</code> and the raw request URI:</p>
|
||||
|
||||
<pre><code>$renderer = new Renderer($config['pages_dirs'], $cache, $adminAuthEnabled, $matomoUrl, $config['matomo_site_id'], $config['site_name']);
|
||||
<pre><code>$renderer = new Renderer($config['pages_dirs'], $cache, $adminAuthEnabled, $matomoUrl, $config['matomo_site_id'], $config['site_name'], $config['content_index_enabled'], $config['debug'], $config['twig_globals'] ?? []);
|
||||
|
||||
if (!$route->found) {
|
||||
$renderer->renderNotFound($requestUri);
|
||||
@@ -239,7 +239,7 @@ $renderer->render($route, $requestUri);</code></pre>
|
||||
|
||||
<h3>Constructing it</h3>
|
||||
|
||||
<p>The first two constructor arguments are the same <code>pagesDirs</code> override-root list every other class here takes, plus a <code>Cache</code> instance (<code>novaconium/src/Cache.php</code>) it writes sidecar-less pages' output to. The remaining four — admin-auth-enabled flag, Matomo URL/site ID, site name — aren't used for routing or rendering logic at all; they're registered as Twig globals (<code>$this->twig->addGlobal(...)</code>) purely so every template can read <code>matomo_url</code>, <code>site_name</code>, etc. without a sidecar having to pass them through manually. A fifth global, <code>is_404</code>, defaults to <code>false</code> here and is overridden per-render — see below.</p>
|
||||
<p>The first two constructor arguments are the same <code>pagesDirs</code> override-root list every other class here takes, plus a <code>Cache</code> instance (<code>novaconium/src/Cache.php</code>) it writes sidecar-less pages' output to. The remaining four — admin-auth-enabled flag, Matomo URL/site ID, site name — aren't used for routing or rendering logic at all; they're registered as Twig globals (<code>$this->twig->addGlobal(...)</code>) purely so every template can read <code>matomo_url</code>, <code>site_name</code>, etc. without a sidecar having to pass them through manually. A fifth global, <code>is_404</code>, defaults to <code>false</code> here and is overridden per-render — see below. The last argument, <code>twigGlobals</code>, carries the project's <code>twig_globals</code> config (see <a href="/admin/docs/config">Configuration</a>); those are registered first, so a colliding name can never replace one of the framework's own globals.</p>
|
||||
|
||||
<h3>What <code>render()</code> actually does, in order</h3>
|
||||
|
||||
|
||||
@@ -243,7 +243,7 @@ final class ContentIndexer
|
||||
*/
|
||||
private static function renderer(array $config): Renderer
|
||||
{
|
||||
return new Renderer($config['pages_dirs'], new Cache($config['cache_dir']));
|
||||
return new Renderer($config['pages_dirs'], new Cache($config['cache_dir']), twigGlobals: $config['twig_globals'] ?? []);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,6 +23,8 @@ final class Renderer
|
||||
|
||||
/**
|
||||
* @param string[] $pagesDirs ordered override roots, most specific first
|
||||
* @param array<string,mixed> $twigGlobals project-defined globals from
|
||||
* the twig_globals config key; framework globals take precedence
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly array $pagesDirs,
|
||||
@@ -33,6 +35,7 @@ final class Renderer
|
||||
string $siteName = 'My Site',
|
||||
bool $contentIndexEnabled = false,
|
||||
private readonly bool $debug = false,
|
||||
array $twigGlobals = [],
|
||||
) {
|
||||
$loader = new FilesystemLoader($this->pagesDirs);
|
||||
// 'debug' also drives PHP error display (see bootstrap.php). When on,
|
||||
@@ -59,6 +62,12 @@ final class Renderer
|
||||
$this->twig->addExtension(new DebugExtension());
|
||||
}
|
||||
$this->twig->addExtension(new SassExtension($this->pagesDirs));
|
||||
// Project globals go in first so the framework's own addGlobal()
|
||||
// calls below overwrite any colliding name — a project can't
|
||||
// accidentally clobber is_404 or matomo_url via twig_globals.
|
||||
foreach ($twigGlobals as $name => $value) {
|
||||
$this->twig->addGlobal((string) $name, $value);
|
||||
}
|
||||
$this->twig->addGlobal('admin_auth_enabled', $adminAuthEnabled);
|
||||
$this->twig->addGlobal('matomo_url', $matomoUrl);
|
||||
$this->twig->addGlobal('matomo_site_id', $matomoSiteId);
|
||||
|
||||
Reference in New Issue
Block a user