diff --git a/system/user/addons/template_sync/Controller/SyncPartials.php b/system/user/addons/template_sync/Controller/SyncPartials.php index b4ed187..08a629c 100644 --- a/system/user/addons/template_sync/Controller/SyncPartials.php +++ b/system/user/addons/template_sync/Controller/SyncPartials.php @@ -13,10 +13,10 @@ public function run() $partialSyncService = ee('template_sync:SyncPartialsService'); // Get partials - $partials = $partialFileService->get('partials'); + $partials = $partialFileService->get('partials', 'partial:'); // Get variables - $variables = $partialFileService->get('variables'); + $variables = $partialFileService->get('variables', 'variable:'); // Sync partials $partialSyncService->run('Snippet', $partials); diff --git a/system/user/addons/template_sync/Service/PartialFileTemplates.php b/system/user/addons/template_sync/Service/PartialFileTemplates.php index 831279b..3628535 100644 --- a/system/user/addons/template_sync/Service/PartialFileTemplates.php +++ b/system/user/addons/template_sync/Service/PartialFileTemplates.php @@ -5,14 +5,17 @@ class PartialFileTemplates { private $returnTemplates = array(); + private $namespace = ''; /** * Get partial file templates from file system * * @return array */ - public function get($path) + public function get($path, $namespace = '') { + $this->namespace = $namespace; + // Set variables $templateBasePath = SYSPATH . 'user/templates/'; $path = $templateBasePath . ee()->config->item('site_short_name') . @@ -26,7 +29,12 @@ public function get($path) // Recursively load files $this->processRecursively($path); - return $this->returnTemplates; + // Reset for next use + $returnTemplates = $this->returnTemplates; + $this->returnTemplates = array(); + $this->namespace = ''; + + return $returnTemplates; } /** @@ -55,7 +63,7 @@ private function processRecursively($path, $prefix = '') // Make sure hidden files (starting with .) are not included if ($pathInfo['filename']) { - $this->returnTemplates[$prefix . $pathInfo['filename']] = $content; + $this->returnTemplates[$this->namespace . $prefix . $pathInfo['filename']] = $content; } } } diff --git a/system/user/addons/template_sync/Service/SyncPartials.php b/system/user/addons/template_sync/Service/SyncPartials.php index aabd6f7..1bd02e5 100644 --- a/system/user/addons/template_sync/Service/SyncPartials.php +++ b/system/user/addons/template_sync/Service/SyncPartials.php @@ -14,7 +14,7 @@ class SyncPartials public function run($model, $data) { $name = $model === 'Snippet' ? 'snippet_name' : 'variable_name'; - $content = $model == 'Snippet' ? 'snippet_contents' : 'variable_data'; + $content = $model === 'Snippet' ? 'snippet_contents' : 'variable_data'; // Get existing partials $partials = ee('Model')->get($model)->all();