public function HIncludeFragmentRenderer::render in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/symfony/http-kernel/Fragment/HIncludeFragmentRenderer.php \Symfony\Component\HttpKernel\Fragment\HIncludeFragmentRenderer::render()
Additional available options:
- default: The default content (it can be a template name or the content)
- id: An optional hx:include tag id attribute
- attributes: An optional array of hx:include tag attributes
Overrides FragmentRendererInterface::render
File
- vendor/
symfony/ http-kernel/ Fragment/ HIncludeFragmentRenderer.php, line 83
Class
- HIncludeFragmentRenderer
- Implements the Hinclude rendering strategy.
Namespace
Symfony\Component\HttpKernel\FragmentCode
public function render($uri, Request $request, array $options = array()) {
if ($uri instanceof ControllerReference) {
if (null === $this->signer) {
throw new \LogicException('You must use a proper URI when using the Hinclude rendering strategy or set a URL signer.');
}
// we need to sign the absolute URI, but want to return the path only.
$uri = substr($this->signer
->sign($this
->generateFragmentUri($uri, $request, true)), strlen($request
->getSchemeAndHttpHost()));
}
// We need to replace ampersands in the URI with the encoded form in order to return valid html/xml content.
$uri = str_replace('&', '&', $uri);
$template = isset($options['default']) ? $options['default'] : $this->globalDefaultTemplate;
if (null !== $this->templating && $template && $this
->templateExists($template)) {
$content = $this->templating
->render($template);
}
else {
$content = $template;
}
$attributes = isset($options['attributes']) && is_array($options['attributes']) ? $options['attributes'] : array();
if (isset($options['id']) && $options['id']) {
$attributes['id'] = $options['id'];
}
$renderedAttributes = '';
if (count($attributes) > 0) {
if (PHP_VERSION_ID >= 50400) {
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
}
else {
$flags = ENT_QUOTES;
}
foreach ($attributes as $attribute => $value) {
$renderedAttributes .= sprintf(' %s="%s"', htmlspecialchars($attribute, $flags, $this->charset, false), htmlspecialchars($value, $flags, $this->charset, false));
}
}
return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
}