Render a View in a form

Components

Rendering Views in a form is super easy thanks to the buildRenderable() method, which builds the render array for the given display. To render a View, you just need to know the machine name of the View and display ID (usually page_1 or block_1). To render the Content View do this:

use Drupal\views\Views;
$view = Views::getView('content');
$form['content'] = $view->buildRenderable('page_1');

About the Author

Goran Nikolovski is a senior developer with over 10 years of experience turning ideas into scalable digital products—from web platforms and mobile apps to AI-powered tools. He is passionate about clean code, creative problem-solving, and shaping the future of digital development.

AI Assistant