You are here

public function DynamicPageCacheTestController::htmlWithCacheContexts in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php \Drupal\dynamic_page_cache_test\DynamicPageCacheTestController::htmlWithCacheContexts()

A route returning a render array (with cache contexts, so cacheable).

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

array A render array.

See also

html()

1 string reference to 'DynamicPageCacheTestController::htmlWithCacheContexts'
dynamic_page_cache_test.routing.yml in core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/dynamic_page_cache_test.routing.yml
core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/dynamic_page_cache_test.routing.yml

File

core/modules/dynamic_page_cache/tests/dynamic_page_cache_test/src/DynamicPageCacheTestController.php, line 66

Class

DynamicPageCacheTestController
Controller routines for dynamic_page_cache_test routes.

Namespace

Drupal\dynamic_page_cache_test

Code

public function htmlWithCacheContexts(Request $request) {
  $build = $this
    ->html();
  $build['dynamic_part'] = [
    '#markup' => $this
      ->t('Hello there, %animal.', [
      '%animal' => $request->query
        ->get('animal'),
    ]),
    '#cache' => [
      'contexts' => [
        'url.query_args:animal',
      ],
    ],
  ];
  return $build;
}