// Load a custom block by id. $block = \Drupal\block\Entity\Block::load('my_block_id'); // Render the block. $block_content = \Drupal::entityTypeManager()->getViewBuilder('block')->view($block);
// Load a menu by name. $tree_parameters = \Drupal\Core\Menu\MenuTreeParameters::create(); $tree = \Drupal::menuTree()->load('main', $tree_parameters); // Render the menu. $menu_tree_output = \Drupal::menuTree()->build($tree); // Get the HTML. $menu_html = \Drupal::service('renderer')->renderRoot($menu_tree_output);This code loads a menu by name, builds the menu tree and renders it as HTML. In conclusion, the PHP Module render is a part of the Drupal CMS system and provides a set of functions that can be used to create reusable components for web pages. The code examples shown here demonstrate its usefulness in rendering blocks and menus.