function JsExampleController::showAccordion
Accordion page implementation.
We're allowing a twig template to define our content in this case, which isn't normally how things work, but it's easier to demonstrate the JavaScript this way.
Return value
array A render array.
1 string reference to 'JsExampleController::showAccordion'
- js_example.routing.yml in modules/
js_example/ js_example.routing.yml - modules/js_example/js_example.routing.yml
File
-
modules/
js_example/ src/ Controller/ JsExampleController.php, line 89
Class
- JsExampleController
- Controller for JavaScript Example description page.
Namespace
Drupal\js_example\ControllerCode
public function showAccordion() {
// We get all the page content from a theme hook. This is not a good
// practice, though: Theme hooks should just theme the content they obtain.
$build['accordion'] = [
'#theme' => 'js_example_accordion',
'#title' => $this->t('Click on sections to expand or collapse them.'),
];
// The usual way to attach a library to a page is adding it to the render
// array via the #attached property. In this case, we added it via the
// template file we use. This is why the following lines are commented out.
//
// $build['accordion']['#attached']['library'][] = 'js_example/accordion';
return $build;
}