I want to take the NID field and display is as the row ID in a Views table. (I can then use that ID as an anchor to jump to the correct row in the table.)

However, I cannot for the life of me, find a way to 'print' the NID value in the views-view-table.html.twig template (I've changed the template name to match my view).

In a views-view-unformatted.html.twig template I've used the following (which works perfectly):


But that doesn't work in the table template.

Finding the correct syntax to print fields in different templates seems to be a mystery.

Thanks in advance for any help you can give.

1 Answer 1


I have tried template_preprocess_views_view_table function. You may also try in your theme's YOURTHEMENAME.theme file to override as follow.

function YOURTHEMENAME_preprocess_views_view_table(&$variables) {
  foreach ($variables['rows'] as $num => $row) {
    $row['attributes']['id'] = $variables['rows'][$num]['columns']['nid']['content'][0]['field_output']['#markup'];

enter image description here

As in above the screen you can see NID field in view is added as id of row in table. Although its showing spaces around nid but id is added further you can refine it as per your requirement.

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.