41 lines
954 B
PHP
41 lines
954 B
PHP
<?php
|
|
|
|
namespace Picea\Extension;
|
|
|
|
use Picea\Compiler\Context;
|
|
|
|
class TitleExtension implements Extension {
|
|
|
|
public string $token = "title";
|
|
|
|
public string $title = "";
|
|
|
|
public function __construct(Context $context) {
|
|
$this->register($context);
|
|
}
|
|
|
|
public function register(Context $context) : void
|
|
{
|
|
$context->pushFunction("title", [ $this, 'handleTitle' ]);
|
|
}
|
|
|
|
public function parse(/*\Picae\Compiler\Context*/ &$context, ?string $arguments, string $token) {
|
|
return "<?php echo title($arguments) ?>";
|
|
}
|
|
|
|
public function handleTitle(? string $set = null) : ? string
|
|
{
|
|
if ( $set === null ) {
|
|
return $this->title;
|
|
}
|
|
else {
|
|
# Fixed a bug where template inheritance was rewriting title
|
|
if ( empty($this->title) ) {
|
|
$this->title = $set;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|