/** * Render the current Renderable for a given context. * * @since 1.0.0 * * @param array $context The context in which to render the Renderable. * * @return string Rendered output of the Renderable. * @throws RuntimeException */ public function render(array $context) { $viewName = $this->getViewName($context); $view = $this->viewBuilder->create($viewName); $context['css_class'] = $this->getCSSClass(); $context['content'] = $this->content; return $view->render($context); }
/** * Render a partial view for a given URI. * * @since 0.2.0 * * @param string $view View identifier to create a view for. * @param array $context Optional. The context in which to render the view. * @param string|null $type Type of view to create. * * @return string Rendered HTML content. */ public function renderPart($view, array $context = null, $type = null) { if (null === $context) { $context = $this->context; } $this->initializeViewBuilder(); $viewObject = $this->builder->create($view, $type); return $viewObject->render($context); }
/** * Render the template for a given context. * * @since 1.0.0 * * @param array $context The context in which to render the template. * * @return string The rendered content. */ public function render(array $context) { $viewName = $this->getViewName($context); $view = $this->viewBuilder->create($viewName); $sanitizerType = $this->config['formats'][$context['format']]['sanitizer']; $sanitizerFactory = new Factory($this->config, 'sanitizers'); $sanitizer = $sanitizerFactory->create($sanitizerType); $output = $view->render($context); return $sanitizer->sanitize($output, $context); }
public function testCustomConfig() { $viewBuilder = new ViewBuilder(ConfigFactory::create(['BrightNucleus' => ['View' => ['EngineFinder' => ['Engines' => ['TestEngine' => 'BrightNucleus\\View\\Tests\\TestEngine']]]]])); $viewBuilder->addLocation(new FilesystemLocation(__DIR__ . '/fixtures', ['.test'])); $view = $viewBuilder->create('custom.engine'); $result = $view->render(['testdata' => 'testvalue']); $this->assertEquals('Test Data = testvalue', $result); }