1234567891011121314151617181920212223242526 |
- <?php
- namespace App\Service;
- use Hyperf\Context\ApplicationContext;
- use Smarty;
- class SmartyRenderer
- {
- protected Smarty $smarty;
- public function __construct()
- {
- $this->smarty = new Smarty();
- $this->smarty->setTemplateDir(BASE_PATH . '/storage/view/');
- $this->smarty->setCompileDir(BASE_PATH . '/runtime/smarty/compile/');
- $this->smarty->setCacheDir(BASE_PATH . '/runtime/smarty/cache/');
- }
- public function render(string $template, array $data): string
- {
- foreach ($data as $key => $value) {
- $this->smarty->assign($key, $value);
- }
- return $this->smarty->fetch($template);
- }
- }
|