function NyanCatThemeEngine::renderTemplate
Renders a template.
Parameters
string $template_file: The name of the template to render, without the file extension.
array $variables: A keyed array of variables that will appear in the output.
Return value
string|\Drupal\Component\Render\MarkupInterface The output generated by the template, plus any debug information.
Overrides ThemeEngineInterface::renderTemplate
File
-
core/
modules/ system/ tests/ modules/ nyan_cat/ src/ NyanCatThemeEngine.php, line 31
Class
- NyanCatThemeEngine
- NYAN NYAN NYAN!
Namespace
Drupal\nyan_catCode
public function renderTemplate(string $template_file, array $variables) : string|MarkupInterface {
$output = str_replace('div', 'nyancat', file_get_contents(\Drupal::root() . '/' . $template_file . '.nyan-cat.html'));
foreach ($variables as $key => $variable) {
if (str_contains($output, '9' . $key)) {
$output = str_replace('9' . $key, Html::escape($variable), $output);
}
}
return $output;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.