Programmatically get View Custom Text I created a view with a "Custom text" field and want to get this field programmatically in Drupal 8.

I have:

$view = Views::getView('my_view');
$view-&gt;execute();
foreach($view-&gt;result as $row){
    $node = Node::load($row-&gt;nid);
    // Get here the view custom field with label "An example view field".
}


The $row field doesn't have the fields, nor the $node.

A screenshot of the view:


I now have:

$customField = $view-&gt;field['nothing'];


customField is an instance of Drupal\views\Plugin\views\field\Custom.

dpm($customField-&gt;render($row));


This returns class Drupal\views\Render\ViewsRenderPipelineMarkup with protectecd string with the same markup: {{ title }} test.

Thanks,
You should have something like

//already loaded
$node = $row-&gt;_entity;


Best way to get properties easily is probably to inspect variables with xdebug

If it is some king of header/footer, you can get the rendered array this way :

$view = \Drupal\views\Views::getView('Your view');
$view-&gt;execute();
/* @var $area \Drupal\views\Plugin\views\area\Text */
$area = reset($view-&gt;header); // $view-&gt;header['area'] or something else
$rendered = $area-&gt;render(); // rendered array


Ok, then :

$view = \Drupal\views\Views::getView('YOUR VIEW');
$view-&gt;execute('YOUR DISPLAY ID OR DEFAULT');
$nothing = $view-&gt;getHandler('YOUR DISPLAY ID OR DEFAULT','field', 'nothing');
$text = $nothing['alter']['text'];