Add scheme and title reference to Template

This commit is contained in:
Giuseppe Criscione 2024-10-06 18:16:35 +02:00
parent 9af3f366c3
commit eac982350e
2 changed files with 18 additions and 3 deletions

View File

@ -5,6 +5,7 @@ namespace Formwork\Templates;
use Closure;
use Formwork\App;
use Formwork\Assets;
use Formwork\Schemes\Scheme;
use Formwork\Site;
use Formwork\Utils\Constraint;
use Formwork\Utils\FileSystem;
@ -25,7 +26,7 @@ class Template implements Stringable
/**
* Create a new Template instance
*/
public function __construct(protected string $name, protected App $app, protected Site $site, protected ViewFactory $viewFactory)
public function __construct(protected string $name, protected Scheme $scheme, protected App $app, protected Site $site, protected ViewFactory $viewFactory)
{
$this->path = $this->app->config()->get('system.templates.path');
}
@ -40,6 +41,16 @@ class Template implements Stringable
return $this->name;
}
public function scheme(): Scheme
{
return $this->scheme;
}
public function title(): string
{
return $this->scheme->title();
}
public function path(): string
{
return $this->path;

View File

@ -2,16 +2,20 @@
namespace Formwork\Templates;
use Formwork\Schemes\Schemes;
use Formwork\Services\Container;
class TemplateFactory
{
public function __construct(protected Container $container)
public function __construct(protected Container $container, protected Schemes $schemes)
{
}
public function make(string $name): Template
{
return $this->container->build(Template::class, compact('name'));
return $this->container->build(Template::class, [
'name' => $name,
'scheme' => $this->schemes->get('pages.' . $name),
]);
}
}