0

I need to render an image from my custom block. So i have to return an renderable array of an image object from my block.

I have written code like this(snippet), and its working fine.

$logo_build = [
       '#theme' => 'image',
       '#width' => $width,
       '#height' => $height,
       '#uri' => $uri,
     ];

     $renderer = \Drupal::service('renderer');
     $renderer->addCacheableDependency($logo_build, $file);

     return [
       'logo' => $logo_build,
     ];

but now, how to set '#cache' value here ?
If it return array like below then i can use '#cache'. But in the above code how to set '#cache' value ?

return array(
     '#cache' => ,
);
7
  • $logo_build = [ '#theme' => 'image', '#width' => $width, '#height' => $height, '#uri' => $uri, '#cache' => [ 'contexts' => abc, 'tags' => xyz, ],]; Try something like this May 16, 2016 at 9:18
  • i have used '#cache' => ['contexts' => ['url.path']] , but its not working in above way. May 16, 2016 at 9:31
  • ['contexts' => ['url.path', 'url.query_args'] u arent passing query arguments May 16, 2016 at 9:35
  • I think 'url.path' is fine, because its working for me outside the $logo_build array May 16, 2016 at 10:05
  • What kind of caching are you looking for? When should the cache be invalidated?
    – Eyal
    May 16, 2016 at 10:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.