/** * Tries to load the resource for a block from a theme. * * @param string $cacheKey The cache key for storing the resource. * @param string $blockName The name of the block to load a resource for. * @param mixed $theme The theme to load the block from. * * @return bool True if the resource could be loaded, false otherwise. */ protected function loadResourceFromTheme($cacheKey, $blockName, $theme) { if ($this->engine->exists($templateName = $theme . '/' . $blockName . '.html.php')) { $this->resources[$cacheKey][$blockName] = $templateName; return true; } return false; }
/** * Locates the applicable template and returns its path. * @return string The template path. */ protected function getTemplatePath() { $paths = ['@custom_webindex_templates/' . self::DEFAULT_TEMPLATE_NAME]; foreach ($paths as $path) { if ($this->templatingEngine->exists($path)) { return $path; } } return 'IliosWebBundle:WebIndex:' . self::DEFAULT_TEMPLATE_NAME; }
/** * Finds the template in all the bundles. * * @param string $templatePath The template to search. * * @return bool|string The string found or false if not found */ protected function findTemplate($templatePath) { foreach ($this->bundles as $bundleName) { $templateName = "{$bundleName}:{$templatePath}"; if ($this->engine->exists($templateName)) { return $templateName; } } return false; }
/** * @param $element * @param $columnName * @return string * @throws Exception */ private function formatColumn($element, $columnName) { $nameArray = explode('.', $columnName); $columnName = $nameArray[0]; $view = $this->repository->getTemplatesPath() . $columnName . '.html.twig'; if ($this->templating->exists($view)) { return $this->templating->render($view, ['element' => $element]); } if (method_exists($element, $columnName)) { return $element->{$columnName}(); } $getter = 'get' . ucfirst($columnName); if (!method_exists($element, $getter)) { throw new Exception($this->translator->trans(self::ERROR_NO_ELEMENT_RENDER_INFO) . ': ' . $columnName); } $result = $element->{$getter}(); if (!isset($nameArray[1])) { if ($result instanceof \DateTime) { return $result->format('d.m.Y'); } return $result; } unset($nameArray[0]); return $result ? $this->formatColumn($result, implode('.', $nameArray)) : ''; }
/** * Gets the RequireJS src * * @return string Returns a string that represents the RequireJS src */ public function src() { if ($this->engine->exists($this->requireJsSrc) && $this->engine->supports($this->requireJsSrc)) { return $this->engine->render($this->requireJsSrc); } return $this->requireJsSrc; }
/** * Locates the applicable message template for a given school and returns its path. * @param SchoolInterface $school * @return string The template path. */ protected function getTemplatePath(SchoolInterface $school) { $paths = ['@custom_email_templates/' . basename($school->getTemplatePrefix() . '_' . self::DEFAULT_TEMPLATE_NAME), '@custom_email_templates/' . self::DEFAULT_TEMPLATE_NAME]; foreach ($paths as $path) { if ($this->templatingEngine->exists($path)) { return $path; } } return 'IliosCoreBundle:Email:' . self::DEFAULT_TEMPLATE_NAME; }
/** * Search for the template in every specified bundle * * @return string Found existing template name */ private function locateTemplate() { foreach ($this->bundles as $bundleName) { $templateName = "{$bundleName}:{$this->templatePath}"; if ($this->engine->exists($templateName)) { return $templateName; } } throw new RuntimeException(sprintf('Template "%s" not found', $this->templatePath)); }
/** * Gets the RequireJS src * * @return string Returns a string that represents the RequireJS src */ public function src() { try { if ($this->engine->exists($this->requireJsSrc) && $this->engine->supports($this->requireJsSrc)) { return $this->engine->render($this->requireJsSrc); } } catch (\InvalidArgumentException $err) { } return $this->requireJsSrc; }
/** * Returns export template for given format like XLIFF1.2. * * @param $format * * @return string * * @throws \Exception */ protected function getTemplate($format) { if (!isset($this->formatFilePaths[$format])) { throw new \Exception(sprintf('No format "%s" configured for webspace export', $format)); } $templatePath = $this->formatFilePaths[$format]; if (!$this->templating->exists($templatePath)) { throw new \Exception(sprintf('No template file "%s" found for webspace export', $format)); } return $templatePath; }
public function renderLocationEmbed($locationId, $viewType, array $parameters, $isInline) { $isDenied = false; try { $location = $this->checkLocation($locationId); if ($location->invisible) { if (isset($this->logger)) { $this->logger->error("Could not render embedded resource: Location #{$locationId} is not visible"); } return null; } } catch (AccessDeniedException $e) { if (isset($this->logger)) { $this->logger->error("Could not render embedded resource: access denied to embed Location #{$locationId}"); } $isDenied = true; } catch (Exception $e) { if ($e instanceof NotFoundHttpException || $e instanceof NotFoundException) { if (isset($this->logger)) { $this->logger->error("Could not render embedded resource: Location #{$locationId} not found"); } return null; } else { throw $e; } } $templateName = $this->getEmbedTemplateName(static::RESOURCE_TYPE_LOCATION, $isInline, $isDenied); if ($templateName === null) { $this->logger->error('Could not render embedded resource: no template configured'); return null; } if (!$this->templateEngine->exists($templateName)) { if (isset($this->logger)) { $this->logger->error("Could not render embedded resource: template '{$templateName}' does not exists"); } return null; } return $this->render($templateName, $parameters); }
/** * @param string $template * @param array $parameters * * @return null|string */ protected function getTemplate($template, array $parameters = []) { return $this->templating->exists($template) ? $this->templating->render($template, $parameters) : null; }
public function exists($name) { return $this->engine->exists($name); }