Get Node Author's Name in Custom Block In the admin area, to create a custom block, I go to:

Structure, Block layout, + Add custom block.


Once I create the custom block in the UI, I see a textarea field called "Body" where I can enter content.

How can I dynamically render the node author's name and profile picture in my custom block. I know I can type it in, but I would like to be able to insert some code (PHP, Twig or token) so that it pull's the author's name and profile image dynamically and prints it on the block. I do not want to use a views block, but a custom block instead.
One way to go about this is block preprocess function to retrieve the block's current node context &amp; insert the relevant variables to be used by your Twig template. For example: 

/**
 * Implements hook_preprocess_HOOK() for block.html.twig.
 */
function MYTHEME_preprocess_block(&amp;$variables) {
  $node = \Drupal::request()-&gt;attributes-&gt;get('node');
  if (!is_null($node)) {
    $uid = $node-&gt;getOwnerId();
    $user = \Drupal\user\Entity\User::load($uid);
    if (!is_null($user)) {
      $username = $user-&gt;getDisplayName();
      $variables['$username'] = $username;
      // {{ username }} will be available within block.html.twig.
    }
  }
}