/** * Searches the layout and page components by a partial file * @return ComponentBase The component object, if found */ public function findComponentByPartial($partial) { foreach ($this->page->components as $component) { $fileName = ComponentPartial::getFilePath($component, $partial); if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; } if (File::isFile($fileName)) { return $component; } } foreach ($this->layout->components as $component) { $fileName = ComponentPartial::getFilePath($component, $partial); if (!strlen(File::extension($fileName))) { $fileName .= '.htm'; } if (File::isFile($fileName)) { return $component; } } return null; }
/** * Searches the layout and page components by a partial file * @param string $partial * @return ComponentBase The component object, if found */ public function findComponentByPartial($partial) { foreach ($this->page->components as $component) { if (ComponentPartial::check($component, $partial)) { return $component; } } foreach ($this->layout->components as $component) { if (ComponentPartial::check($component, $partial)) { return $component; } } return null; }
public function onExpandMarkupToken() { if (!($alias = post('tokenName'))) { throw new ApplicationException(trans('cms::lang.component.no_records')); } // Can only expand components at this stage if (!($type = post('tokenType')) && $type != 'component') { return; } if (!($names = (array) post('component_names')) || !($aliases = (array) post('component_aliases'))) { throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); } if (($index = array_get(array_flip($aliases), $alias, false)) === false) { throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); } if (!($componentName = array_get($names, $index))) { throw new ApplicationException(trans('cms::lang.component.not_found', ['name' => $alias])); } $manager = ComponentManager::instance(); $componentObj = $manager->makeComponent($componentName); $partial = ComponentPartial::load($componentObj, 'default'); $content = $partial->getContent(); $content = str_replace('__SELF__', $alias, $content); return $content; }
public static function makeBaguetteGallery($images, $layout = "", $class = "") { // Set component properties if (empty($class)) { $class = self::$defaultClass; } if (empty($layout)) { $layout = self::$defaultLayout; } $parameters = ['layout' => $layout, 'class' => $class, 'images' => []]; foreach ($images as $key => $val) { $parameters['images'][$key] = new BaguetteImage($val, true); } // Get twig runtime $twig = App::make('twig.environment'); $partial = null; $result = ""; // Create an instance of the component $manager = ComponentManager::instance(); $component = $manager->makeComponent(self::$componentName, null, $parameters); $component->init(); $component->alias = self::$componentName; // Try first to find a partial from the theme $overrideName = $component->alias . '/' . $parameters['layout']; if (Filesystem::isFile(Theme::getActiveTheme()->getPath() . '/partials/' . $overrideName . '.htm')) { $partial = Partial::loadCached(Theme::getActiveTheme(), $overrideName); } // If not found we use one from the plugin if (is_null($partial)) { if (Filesystem::isFile(plugins_path() . '/nsrosenqvist/baguettegallery/components/baguettegallery/' . $parameters['layout'] . '.htm')) { $partial = ComponentPartial::loadCached($component, $parameters['layout']); } else { $partial = ComponentPartial::loadCached($component, self::$defaultLayout); } } // Render the component if (!is_null($partial) && !empty($images)) { $template = $twig->loadTemplate($partial->getFullPath()); $result = $template->render($parameters); } return $result; }