Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Fixed twig for email templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
seehat committed Dec 19, 2022
1 parent 00d7592 commit 2df5634
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amteich/kirby-twig",
"description": "Twig templating support for Kirby CMS",
"type": "kirby-plugin",
"version": "4.2.2",
"version": "4.2.3",
"license": "MIT",
"authors": [
{
Expand Down
19 changes: 12 additions & 7 deletions src/classes/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class Template extends \Kirby\Cms\Template
{
private static $twig;
private string $twigpath;

/**
* Creates a new template object
Expand Down Expand Up @@ -65,6 +66,7 @@ public function file(): ?string

if ($this->hasDefaultType() === true) {

$this->twigpath = $this->name() . '.twig';
$base = $this->root() . '/' . $this->name();
$twig = $base . '.twig';
$php = $base . '.php';
Expand All @@ -86,6 +88,7 @@ public function file(): ?string
}

$name = $this->name() . '.' . $type;
$this->twigpath = $name . '.twig';
$base = $this->root() . '/' . $name;
$twig = $base . '.twig';
$php = $base . '.php';
Expand All @@ -112,14 +115,16 @@ public function render(array $data = []): string
{
if ($this->isTwig()) {

static::$twig->addGlobal('kirby', $data['kirby']);
static::$twig->addGlobal('site', $data['site']);
static::$twig->addGlobal('pages', $data['pages']);
static::$twig->addGlobal('page', $data['page']);
static::$twig->addGlobal('user', $data['kirby']->user());
static::$twig->addGlobal('users', $data['kirby']->users());
$kirby = kirby();
static::$twig->addGlobal('kirby', $kirby);
static::$twig->addGlobal('site', $kirby->site());
static::$twig->addGlobal('pages', $kirby->site()->pages());
static::$twig->addGlobal('page', $kirby->site()->page());
static::$twig->addGlobal('user', $kirby->user());
static::$twig->addGlobal('users', $kirby->users());

return static::$twig->renderPath($this->name() . '.' . $this->extension(), $data, true);
// $this->name() . '.' . $this->extension()
return static::$twig->renderPath($this->twigpath, $data, true);
}
return parent::render($data);
}
Expand Down

0 comments on commit 2df5634

Please sign in to comment.