setCache(new FileCache(['cache_dir' => storage_path('framework/cache/data')])); $template->parse($templateContent); // 渲染模板并返回结果 return $template->render($data); } protected static function findTemplate(string $templateName): ?string { // 如果模板名没有以 .liquid 结尾,则添加 .liquid 扩展名 if (pathinfo($templateName, PATHINFO_EXTENSION) !== 'liquid') { $templateName .= '.liquid'; } // 处理模板名中的 . 号,将其转换为目录分隔符(不包括扩展名) $templateNameWithoutExtension = pathinfo($templateName, PATHINFO_FILENAME); $templatePathSegments = explode('.', $templateNameWithoutExtension); $relativePath = implode(DIRECTORY_SEPARATOR, $templatePathSegments) . '.liquid'; // 构建预期的模板路径 $expectedPath = self::$baseTemplatePath . DIRECTORY_SEPARATOR . $relativePath; if (File::exists($expectedPath)) { return $expectedPath; } return null; } }