diff --git a/render_example/src/Controller/RenderExampleController.php b/render_example/src/Controller/RenderExampleController.php index 30c509c..296dce5 100644 --- a/render_example/src/Controller/RenderExampleController.php +++ b/render_example/src/Controller/RenderExampleController.php @@ -168,8 +168,8 @@ class RenderExampleController extends ControllerBase { // corresponds to the variable {{ items }} in the item-list.twig.html // template file. '#items' => [ - 'value' => $this->t('This is some more text that we need in the list'), - 'attributes' => ['class' => ['item_list__item']], + $this->t('This is an item in the list'), + $this->t('This is some more text that we need in the list'), ], ]; @@ -386,7 +386,33 @@ class RenderExampleController extends ControllerBase { ], ]; - return $build; + $output = array(); + // We are going to create a new output render array that pairs each + // example with a set of helper render arrays. These are used to display + // the description as a title and the unrendered content alongside the + // examples. + foreach (Element::children($build) as $key) { + if (isset($build[$key])) { + $output[$key] = [ + '#theme' => 'render_array', + 'description' => [ + '#type' => 'markup', + '#markup' => isset($build[$key]['#description']) ? $build[$key]['#description'] : '', + ], + 'rendered' => $build[$key], + 'unrendered' => [ + '#type' => 'markup', + '#markup' => htmlentities(\Drupal\Component\Utility\Variable::export($build[$key])), + ], + ]; + } + } + + foreach (Element::properties($build) as $key) { + $output[$key] = $build[$key]; + } + + return $output; } /**