From 7437292798c0c8ebea2a0438b4501c1f35dce954 Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sat, 20 Dec 2025 13:24:05 -0500 Subject: [PATCH 1/2] add blade support for CMS partials --- modules/cms/classes/Controller.php | 12 +++++++++--- modules/cms/classes/Partial.php | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/modules/cms/classes/Controller.php b/modules/cms/classes/Controller.php index fa0d38f0fc..ed61fff7fa 100644 --- a/modules/cms/classes/Controller.php +++ b/modules/cms/classes/Controller.php @@ -25,6 +25,7 @@ use Winter\Storm\Exception\ValidationException; use Winter\Storm\Parse\Bracket as TextParser; use Illuminate\Http\RedirectResponse; +use Illuminate\Support\Facades\Blade; /** * The CMS controller class. @@ -1065,9 +1066,14 @@ public function renderPartial($name, $parameters = [], $throwException = true) * Render the partial */ CmsException::mask($partial, 400); - $this->getLoader()->setObject($partial); - $template = $this->getTwig()->load($partial->getFilePath()); - $partialContent = $template->render(array_merge($parameters, $this->vars)); + if (str_ends_with($partial->fileName, '.blade.php')) { + $partialContent = Blade::render($partial->content, $this->vars); + } + else { + $this->getLoader()->setObject($partial); + $template = $this->getTwig()->load($partial->getFilePath()); + $partialContent = $template->render(array_merge($parameters, $this->vars)); + } CmsException::unmask(); if ($partial instanceof Partial) { diff --git a/modules/cms/classes/Partial.php b/modules/cms/classes/Partial.php index 6a8287456f..4b4a69579b 100644 --- a/modules/cms/classes/Partial.php +++ b/modules/cms/classes/Partial.php @@ -13,6 +13,8 @@ class Partial extends CmsCompoundObject */ protected $dirName = 'partials'; + protected $allowedExtensions = ['htm', 'blade']; + /** * Returns name of a PHP class to us a parent for the PHP class created for the object's PHP section. * @return string Returns the class name. @@ -21,4 +23,29 @@ public function getCodeClassParent() { return PartialCode::class; } + + /** + * Returns the base file name and extension. Applies a default extension, if none found. + */ + public function getFileNameParts($fileName = null) + { + if ($fileName === null) { + $fileName = $this->fileName; + } + + if (!strlen($extension = pathinfo($fileName, PATHINFO_EXTENSION))) { + $extension = $this->defaultExtension; + $baseFile = $fileName; + } + elseif (($extension = pathinfo($fileName, PATHINFO_EXTENSION)) === 'blade') { + $extension = 'php'; + $baseFile = $fileName; + } + else { + $pos = strrpos($fileName, '.'); + $baseFile = substr($fileName, 0, $pos); + } + + return [$baseFile, $extension]; + } } From 3d80d85993e89e0ace85dd010a690ec5218a9c6e Mon Sep 17 00:00:00 2001 From: Marc Jauvin Date: Sat, 20 Dec 2025 14:11:58 -0500 Subject: [PATCH 2/2] add Backend partials blade support --- modules/system/traits/ViewMaker.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/modules/system/traits/ViewMaker.php b/modules/system/traits/ViewMaker.php index ab099e3daa..10860f4999 100644 --- a/modules/system/traits/ViewMaker.php +++ b/modules/system/traits/ViewMaker.php @@ -1,11 +1,12 @@ vars, $extraParams); + if (str_ends_with($filePath, '.blade.php')) { + $fileContent = file_get_contents($filePath); + return Blade::render($fileContent, $vars); + } + $obLevel = ob_get_level(); ob_start();