Skip to content

Instantly share code, notes, and snippets.

@alokstha1
Created April 19, 2024 05:13
Show Gist options
  • Save alokstha1/0c43b081d0a2e70ab376b0ff0a214e86 to your computer and use it in GitHub Desktop.
Save alokstha1/0c43b081d0a2e70ab376b0ff0a214e86 to your computer and use it in GitHub Desktop.
Load a view of a FIELD type for a profile in Drupal
use Drupal\node\Entity\Node;
use Drupal\taxonomy\Entity\Term;
use Drupal\views\ViewExecutable;
use Drupal\views\Views;
use Drupal\Core\Render;
$nid = 1;
$entity_type = 'node';
$view_mode = 'teaser';
$builder = \Drupal::service('entity_type.manager')->getViewBuilder($entity_type);
$storage = \Drupal::service('entity.manager')->getStorage($entity_type);
$node = $storage->load($nid);
$build = $builder->view($node, $view_mode);
$output = \Drupal::service('renderer')->render($node);
var_dump($node);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment