function 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 53
Class
- HIncludeFragmentRenderer
- Implements the Hinclude rendering strategy.
Namespace
Symfony\Component\HttpKernel\FragmentCode
public function render(string|ControllerReference $uri, Request $request, array $options = []) : Response {
if ($uri instanceof ControllerReference) {
$uri = (new FragmentUriGenerator($this->fragmentPath, $this->signer))
->generate($uri, $request);
}
// 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 = $options['default'] ?? $this->globalDefaultTemplate;
if (null !== $this->twig && $template && $this->twig
->getLoader()
->exists($template)) {
$content = $this->twig
->render($template);
}
else {
$content = $template;
}
$attributes = isset($options['attributes']) && \is_array($options['attributes']) ? $options['attributes'] : [];
if (isset($options['id']) && $options['id']) {
$attributes['id'] = $options['id'];
}
$renderedAttributes = '';
if (\count($attributes) > 0) {
$flags = \ENT_QUOTES | \ENT_SUBSTITUTE;
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));
}