I want to save the node title in a variable using: themename_preprocess_views_view_field(), becuase I want to print a the node title above the field.

But when I try to save the title with:

themename_preprocess_views_view_field() {
$variables['node_title'] = $variables['field']->original_value ->    string;

I get Error: Cannot access protected property Drupal\Core\Render\Markup::$string in themename_preprocess_views_view_field() (line 123 of themes/custom/themename/themename.theme).

how can I save this variable so I can print it in the views-view-field.html.twig file?

1 Answer 1


Solution: The way to do this is to add an address Field in the View as Content datasource: address in the Admin GUI.

And select Use entity field rendering.

Under REWRITE RESULTS Select: Override the output of this field with custom text

And in the textbox I added in my case:

{{ title }}
{{ field_address }}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.